pt-query-digest分析Mysql慢查询,Query-Digest-UI生成报表

pt-query-digest分析Mysql慢查询,Query-Digest-UI生成报表


下载地址:

http://www.percona.com/software

https://github.com/kormoc/Query-Digest-UI


1Percona Toolkit

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

PT安装:


  1. #wget http://www.percona.com/redir/downloads/percona-toolkit/LATEST/percona-toolkit-2.1.5-1.noarch.rpm

  2. #yum install -y percona-toolkit-2.1.5-1.noarch.rpm

工具安装目录在:/usr/bin

或者tar.gz包安装


  1. #wget http://www.percona.com/redir/downloads/percona-toolkit/LATEST/percona-toolkit-2.1.5.tar.gz

  2. #tar percona-toolkit-2.1.5.tar.gz

  3. #cd percona-toolkit-2.1.5

  4. #perl Makefile.PL

  5. #make

  6. #make install

工具安装目录在:/usr/local/bin

可以使用pt-query-digest处理MySQL的慢查询日志和存储历史审查趋势分析到query_review_history表值。

详细导入可以查看官方帮助文档和表属性说明:

http://www.mysqlperformanceblog.com/2012/08/28/hidden-columns-of-query_review_history/

http://code.google.com/p/maatkit/wiki/EventAttributes

 

例如:


  1. pt-query-digest --review h=localhost,D=percona,t=query_review,p=pass,u=percona

  2. --review-history h=localhost,D=percona,t=query_review_history,p=pass,u=percona

  3. --filter=" $event->{Bytes} = length($event->{arg}) and $event->{hostname}="$HOSTNAME"" mysqld-slow-queries.log

 

$ HOSTNAME反映当前机器的主机名。更换$ HOSTNAME必要的主机名,如果你从另一台服务器上复制的慢查询日志。有主机名设置过滤查询数据库中聚合来自多个服务器的查询速度慢的可能是有用的。

例子:


  1. pt-query-digest --review h=localhost,D=query,t=query_review,p=querypass,u=query --review-history h=localhost,D=query,t=query_review_history,p=querypass,u=query --filter=" $event->{Bytes} = length($event->{arg}) and $event->{hostname}="$HOSTNAME"" /tmp/slow_query.txt

 

查看表结果:

 

2Query-Digest-UI

其实,这是一个非常简单和直接的工具,浏览和统计Mysql慢查询,基于AJAXWeb界面。

配置Query-Digest-UI

下载:

wget https://nodeload.github.com/kormoc/Query-Digest-UI/zip/master

unzip Query-Digest-UI-master.zip

 

LAMP或是LNMP环境下运行,需要注意的是php必须支持pdo_mysql模块。

修改配置文件数据库信息:

cp config.php.example  config.php

 


  1. $reviewhost = array(

  2. // Replace hostname and database in this setting

  3. // use host=hostname;port=portnum if not the default port

  4. 'dsn' => 'mysql:host=192.168.15.178;port=3306;dbname=query',

  5. 'user' => 'query',

  6. 'password' => 'querypass',

  7. // See http://www.percona.com/doc/percona-toolkit/2.1/pt-query-digest.html#cmdoption-pt-query-digest--review

  8. 'review_table' => 'query_review',

  9. // This table is optional. You don't need it, but you lose detailed stats

  10. // Set to a blank string to disable

  11. // See http://www.percona.com/doc/percona-toolkit/2.1/pt-query-digest.html#cmdoption-pt-query-digest--review-history

  12. 'history_table' => 'query_review_history',

  13. );

 

效果如图:

 

另外mk-query-digestBox Anemometer工具也可以实现,如果有兴趣大家可以测试下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值