Mysql中Anemometer怎么用

发布时间:2021-10-29 17:18:37 作者:小新
来源:亿速云 阅读:206

这篇文章给大家分享的是有关Mysql中Anemometer怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

准备条件:
1.MySQL开启慢查询


2.安装Percona Toolkit
rpm -qa|grep percona
percona-toolkit-2.2.7-1


3.下载Anemometer
官网:https://github.com/box/Anemometer


4.准备好php相关模块(或者yum)


5.启动apache服务
rpm -qa|grep http
httpd-2.2.3-45.el5


安装:
1.安装Percona Toolkit:
rpm -ivh percona-toolkit-2.2.7-1.noarch.rpm


2.将Anemometer文件包解压,重命名为anemometer,并移动到/var/www/html 下(apache默认路径)
pwd
/var/www/html/anemometer


3.安装php相关模块:
  rpm -qa|grep php
php53-common-5.3.3-1.el5
php53-bcmath-5.3.3-1.el5
php53-mysql-5.3.3-1.el5
php53-dba-5.3.3-1.el5
php53-cli-5.3.3-1.el5
php53-gd-5.3.3-1.el5
php53-5.3.3-1.el5
php53-pdo-5.3.3-1.el5
NOTE:
PHP版本要大于5.3,否则就报错,如:
Anemometer requires PHP 5.3 or newer. You have 5.1.6
除此之外还需要:bcmath
rpm -qa|grep bcmath
php53-bcmath-5.3.3-1.el5


4.执行setup 脚本,创建用户:
[root@/var/www/html/anemometer]mysql -uroot -pxxx < install.sql
[root@/var/www/html/anemometer]mysql -uroot -pxxx
mysql > grant all on slow_query_log.* to 'anemometer'@'%' identified by 'test';
mysql > grant select on *.* to  'anemometer'@'%';
mysql > grant all on slow_query_log.* to 'anemometer'@'localhost';
mysql > grant select on *.* to  'anemometer'@'localhost';




5.将慢查询日志通过pt-query-digest分析后存入数据库中:
pt 版本小于2.2版本的语句:
pt-query-digest --user=anemometer --password=test \
                  --review h=db.example.com,D=slow_query_log,t=global_query_review \
                  --review-history h=db.example.com,D=slow_query_log,t=global_query_review_history \
                  --no-report --limit=0% \ 
                  --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"" \ 
                  /root/test/localhost-slow.log


pt 版本大于2.2版本的语句:
pt-query-digest --user=anemometer --password=test --review h=hd-119-186,D=slow_query_log,t=global_query_review --history h=hd-119-186,D=slow_query_log,t=global_query_review_history --no-report --limit=0% --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"" /root/test/localhost-slow.log


执行这个操作后,将会把慢日志分析后存入mysql的slow_query_log数据库。


NOTE:
记得保证相应 '用户'@'主机' 的访问权限




6.修改可视界面的配置信息:
cd /var/www/html/anemometer/conf
cp sample.config.inc.php config.inc.php
vi config.inc.php
 Mysql中Anemometer怎么用
以及:
 Mysql中Anemometer怎么用

NOTE:
主机名一定要修改正确,不能保留为localhost,否则会导致最终界面无法访问。






7.最终本地通过IP访问:
http://192.168.44.130/anemometer
 Mysql中Anemometer怎么用


查询后可获得慢查询日志的结果:
 
Mysql中Anemometer怎么用




补充:如何监控多个数据库

  1. [root@RZ-SI1-DB-14 conf]# ll

  2. total 40

  3. -rwxr-xr-x 1 root root 15504 Oct 12 14:51 config.inc.php                   ###新版都不需要修改里面的配置了,只需要修改下面的datasource

  4. -rwxrwxrwx 1 root root   314 Oct 12 14:54 datasource_si1.inc.php

  5. -rwxr-xr-x 1 root root   314 Oct 12 15:05 datasource_st1.inc.php         ---配置多个datasource,si1 st1 机器上分别导入install.sql  并pt-query-digest 慢日志进去

  6. -rwxrwxrwx 1 root root     0 Oct 13  2016 index.html

  7. -rwxrwxrwx 1 root root 15487 Oct 13  2016 sample.config.inc.php


[root@RZ-SI1-DB-14 conf]# more datasource_si1.inc.php 
<?php
$conf['datasources']['si1'] = array(
        'host'  => '10.38.96.132',
        'port'  => 3306,
        'db'    => 'slow_query_log',
        'user'  => 'xxxxxx',
        'password' => 'xxxxxx',
        'tables' => array(
                'global_query_review' => 'fact',
                'global_query_review_history' => 'dimension'
        ),
        'source_type' => 'slow_query_log'
);


[root@RZ-SI1-DB-14 conf]# more datasource_st1.inc.php 
<?php
$conf['datasources']['st1'] = array(
        'host'  => '10.38.96.128',
        'port'  => 3306,
        'db'    => 'slow_query_log',
        'user'  => 'xxxxxxx',
        'password' => 'xxxxxxxx',
        'tables' => array(
                'global_query_review' => 'fact',
                'global_query_review_history' => 'dimension'
        ),
        'source_type' => 'slow_query_log'
);

Mysql中Anemometer怎么用

感谢各位的阅读!关于“Mysql中Anemometer怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. Anemometer图形化显示MySQL慢日志的工具搭建使用
  2. 使用Anemometer基于pt-query-digest将MySQL慢查询可视化

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

anemometer mysql

上一篇:有哪些CSS基础知识

下一篇:Mysql数据分组排名实现的示例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》