码迷,mamicode.com
首页 > 其他好文 > 详细

Anemometer 分析慢查

时间:2020-01-04 22:16:46      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:disk   plain   fas   命令行   可视化工具   server   lamp环境   limit   error   

anemometer介绍及部署

Anemometer可以把MySQL慢查询可视化,方便我们去找出和分析慢询语句.anemometer基于Percona Toolkit
Percona Toolkit是一组高级的命令行工具,用来管理 MySQL 和系统任务,主要包括:
1、验证主节点和复制数据的一致性
2、有效的对记录行进行归档
3、找出重复的索引
4、总结 MySQL 服务器
5、从日志和 tcpdump 中分析查询
6、问题发生时收集重要的系统信息

安装Percona Toolkit

~]$ sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
~]$ sudo yum install percona-toolkit
~]$ sudo rpm -ql  percona-toolkit  //
/usr/bin/pt-align
/usr/bin/pt-archiver
/usr/bin/pt-config-diff
/usr/bin/pt-deadlock-logger
/usr/bin/pt-diskstats
/usr/bin/pt-duplicate-key-checker
/usr/bin/pt-fifo-split
/usr/bin/pt-find
/usr/bin/pt-fingerprint
/usr/bin/pt-fk-error-logger
/usr/bin/pt-heartbeat
/usr/bin/pt-index-usage
/usr/bin/pt-ioprofile
/usr/bin/pt-kill
/usr/bin/pt-mext
/usr/bin/pt-mongodb-query-digest
/usr/bin/pt-mongodb-summary
/usr/bin/pt-mysql-summary
/usr/bin/pt-online-schema-change
/usr/bin/pt-pmp
/usr/bin/pt-query-digest
/usr/bin/pt-show-grants
/usr/bin/pt-sift
/usr/bin/pt-slave-delay
/usr/bin/pt-slave-find
/usr/bin/pt-slave-restart
/usr/bin/pt-stalk
/usr/bin/pt-summary
/usr/bin/pt-table-checksum
/usr/bin/pt-table-sync
/usr/bin/pt-table-usage
/usr/bin/pt-upgrade
/usr/bin/pt-variable-advisor
/usr/bin/pt-visual-explain

获取anemometer

github: https://github.com/box/Anemometer
安装好lnmp或lamp环境

~]$ git clone git://github.com/box/Anemometer.git
~]$ sudo mv anemometer/ /var/www/

导入数据并授权

~]$ sudo mysql -uroot -pAa123456 < /var/www/anemometer/mysql56-install.sql
> grant all on slow_query_log.* to 'anemometer'@'%' identified by 'anem**0815';
> grant all on slow_query_log.* to 'anemometer'@'localhost' identified by 'anem**0815';
> grant select on *.* to  'anemometer'@'%';
> grant select on *.* to  'anemometer'@'localhost';
> flush privileges;

修改web页面的配置

~]$ cd /var/www/anemometer/conf/
conf]$ cp sample.config.inc.php config.inc.php
conf]$ vim config.inc.php
 'explain'       =>      function ($sample) {
.......
.....
$conn['user'] = 'anemometer';
$conn['password'] = 'anem**0815';

~]$ sudo vim /var/www/anemometer/conf/datasource_localhost.inc.php
$conf['datasources']['localhost'] = array(
        'host'  => 'localhost',
        'port'  => 3306,
        'db'    => 'slow_query_log',
        'user'  => 'anemometer',
        'password' => 'anem**0815',

添加个虚拟主机的配置

配置

~]$ sudo vim /etc/nginx/conf.d/Anemometer.conf
server {
        listen 80;
        server_name explain.aa.com;
        index index.htm index.html index.php;
        root /var/www/anemometer;


        location ~ \.php$ {
                fastcgi_pass   unix:/dev/shm/php-cgi.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }


        location / {

        }
        access_log  /var/log/nginx/anem.log main;
        error_log   /var/log/nginx/anem_error.log;
}

服务重启

~]$ sudo nginx -s reload
~]$ sudo chown -R nginx.nginx /var/www/

访问
http://explain.aa.com/

Table 'slow_query_log.global_query_review' doesn't exist (1146)  # 错误提示

前面说了这可视化工具基于percona-toolkit,现在我们还没用上这工具呢

使用pt工具导入mysql慢查询日志

~]$ sudo pt-query-digest --user=anemometer --password=anem**0815 --socket=/var/lib/mysql/mysql.sock > --review h=localhost,D=slow_query_log,t=global_query_review > --history h=localhost,D=slow_query_log,t=global_query_review_history > --no-report --limit=0% --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"" /var/lib/mysql/mysql-slow.log
*******************************************************************
  at /bin/pt-query-digest line 11914.

/var/lib/mysql/mysql-slow.log:   0% 01:11:07 remain
/var/lib/mysql/mysql-slow.log:   1% 01:10:33 remain
/var/lib/mysql/mysql-slow.log:   2% 01:09:39 remain
/var/lib/mysql/mysql-slow.log:   2% 01:09:04 remain
/var/lib/mysql/mysql-slow.log:   3% 01:08:32 remain
/var/lib/mysql/mysql-slow.log:   4% 01:08:15 remain   # 导入过程比较慢

远程日志分析

将其它数据库服务器上的慢查询日志拉取到本地进行分析

Anemometer 分析慢查

标签:disk   plain   fas   命令行   可视化工具   server   lamp环境   limit   error   

原文地址:https://www.cnblogs.com/knmax/p/12150357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!