使用Anemometer分析MySQL慢查询记录
数据库管理员一般是用percona的toolkit工具来分析MySQL慢查询记录,但是不够直观。
下面介绍一款比较直观的工具来统计分析MySQL慢查询记录anemometer。
在使用之前需要安装percona的toolkit工具,anemometer提供web界面。
anemometer介绍参见:https://github.com/box/Anemometer/wiki
1. 安装
# git clone https://github.com/box/Anemometer.git anemometer
# cd anemometer
|
1
2
3
|
# cd /data/www/my.ttlsa.com
# git clone https://github.com/box/Anemometer.git anemometer
# cd anemometer
|
2. 创建表和用户名
mysql -e "grant ALL ON slow_query_log.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.com';"
mysql -e "grant SELECT ON *.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.com';"
|
1
2
3
|
mysql<install.sql
mysql-e"grant ALL ON slow_query_log.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.com';"
mysql-e"grant SELECT ON *.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.com';"
|
3. 分析MySQL慢日志
--review D=slow_query_log,t=global_query_review \
--review-history D=slow_query_log,t=global_query_review_history \
--no-report --limit=0% --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"" /data/log/mysql/slow.log
|
1
2
3
4
|
# pt-query-digest --user=anemometer --password=superSecurePass \
--reviewD=slow_query_log,t=global_query_review\
--review-historyD=slow_query_log,t=global_query_review_history\
--no-report--limit=0%--filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"" /data/log/mysql/slow.log
|
4. 配置anemometer
# vi conf/config.inc.php
$conf['datasources']['localhost'] = array(
'host' => 'localhost',
'port' => 3306,
'db' => 'slow_query_log',
'user' => 'anemometer',
'password' => 'my.ttlsa.com',
'tables' => array(
'global_query_review' => 'fact',
'global_query_review_history' => 'dimension'
),
'source_type' => 'slow_query_log'
);
$conf['plugins'] = array(
'visual_explain' => '/usr/bin/pt-visual-explain',
'query_advisor' => '/usr/bin/pt-query-advisor',
#... other lines
$conn['user'] = 'anemometer';
$conn['password'] = 'my.ttlsa.com';
return $conn;
},
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# cp conf/sample.config.inc.php conf/config.inc.php
# vi conf/config.inc.php
$conf['datasources']['localhost']=array(
'host' =>'localhost',
'port' =>3306,
'db' =>'slow_query_log',
'user' =>'anemometer',
'password'=>'my.ttlsa.com',
'tables'=>array(
'global_query_review'=>'fact',
'global_query_review_history'=>'dimension'
),
'source_type'=>'slow_query_log'
);
$conf['plugins']=array(
'visual_explain'=>'/usr/bin/pt-visual-explain',
'query_advisor'=>'/usr/bin/pt-query-advisor',
#... other lines
$conn['user']='anemometer';
$conn['password']='my.ttlsa.com';
return$conn;
},
|
5. 自动化处理
postrotate
pt-query-digest --user=anemometer --password=superSecurePass \
--review D=slow_query_log,t=global_query_review \
--review-history D=slow_query_log,t=global_query_review_history \
--no-report --limit=0% --filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\"" /data/log/mysql/slow.log.1
endscript
|
1
2
3
4
5
6
7
|
# vi /etc/logrotate.d/mysql
postrotate
pt-query-digest--user=anemometer--password=superSecurePass\
--reviewD=slow_query_log,t=global_query_review\
--review-historyD=slow_query_log,t=global_query_review_history\
--no-report--limit=0%--filter=" \$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\""/data/log/mysql/slow.log.1
endscript
|
这样就可以通过my.ttlsa.com/anemometer来访问查看慢查询了。
参考文档:
https://www.box.com/blog/optimizing-mysql-performance-at-scale-with-anemometer-2/
http://isadba.com/?p=655
使用Anemometer分析MySQL慢查询记录的更多相关文章
- 十分钟部署Anemometer作为Mysql慢查询可视化系统
前言 采用Anemometer将Mysql慢查询日志可视化,可以更便捷的查询慢查询日志,并根据时间戳进行历史查询.如下是单机版Anemometer部署的演示,实际应用中,为安全起见,建议把anemom ...
- 企业级中带你ELK如何实时收集分析Mysql慢查询日志
什么是Mysql慢查询日志? 当SQL语句执行时间超过设定的阈值时,便于记录到指定的日志文件中或者表中,所有记录称之为慢查询日志 为什么要收集Mysql慢查询日志? 数据库在运行期间,可能会存在这很多 ...
- 利用pt-query-digest分析MySQL慢查询
1.用法与参数说明 pt-query-digest [OPTIONS] [FILES] [DSN] --create-review-table ##当使用--review参数把分析结果输出到表中时,如 ...
- linux上开启和分析mysql慢查询日志
本人qq群也有许多的技术文档,希望可以为你提供一些帮助(非技术的勿加). QQ群: 281442983 (点击链接加入群:http://jq.qq.com/?_wv=1027&k=29Lo ...
- mysql随机查询记录的高效率方法
mysql使用rand随机查询记录的高效率方法 一直以为mysql随机查询几条数据,就用 SELECT * FROM `table` ORDER BY RAND() LIMIT 5 就可以了. 但是真 ...
- MYSQL获得查询记录的行号
对于获得查询记录的行号这一功能,Oracle 中可以使用标准方法(8i版本以上),也可以使用非标准的ROWNUM,MS SQL Server 则在 2005 版本中提供了ROW_NUMBER()函数. ...
- mysqlsla 分析mysql慢查询日志
发现有一个工具mysqlsla,分析查询日志比 mysqldumpslow分析的会更清晰明了! 安装mysqlsla: 下载mysqlsla-2.03.tar.gz [root@yoon export ...
- 基于binlog来分析mysql的行记录修改情况(python脚本分析)
最近写完mysql flashback,突然发现还有有这种使用场景:有些情况下,可能会统计在某个时间段内,MySQL修改了多少数据量?发生了多少事务?主要是哪些表格发生变动?变动的数量是怎 ...
- 基于binlog来分析mysql的行记录修改情况
https://www.cnblogs.com/xinysu/archive/2017/05/26/6908722.html import pymysqlfrom pymysql.cursors im ...
随机推荐
- [转]Python机器学习工具箱
原文在这里 Python在科学计算领域,有两个重要的扩展模块:Numpy和Scipy.其中Numpy是一个用python实现的科学计算包.包括: 一个强大的N维数组对象Array: 比较成熟的(广播 ...
- MySQL数据库select语句的使用方法
select语句可 以用回车分隔 $sql="select * from article where id=1"和 $sql="select * from article ...
- CareerCup Facebook Total number of substring palindrome
Write a function for retrieving the total number of substring palindromes. For example the input is ...
- Direct2D教程VI——转换(Transform)
目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...
- OpenGL ES 3.0之Uniform详解
Uniform是变量类型的一种修饰符,是OpenGL ES 中被着色器中的常量值,使用存储各种着色器需要的数据,例如:转换矩阵.光照参数或者颜色. uniform 的空间被顶点着色器和片段着色器分享 ...
- robot framework + python实现http接口自动化测试框架
https://www.jianshu.com/p/6d1e8cb90e7d 前言 下周即将展开一个http接口测试的需求,刚刚完成的java类接口测试工作中,由于之前犯懒,没有提前搭建好自动化回归测 ...
- 内建DNS服务器--BIND
参考 BIND 官网:http://www.isc.org/downloads/bind/ 1.系统环境说明 [root@clsn6 ~]# cat /etc/redhat-release CentO ...
- 安装logstash+kibana+elasticsearch+redis搭建集中式日志分析平台
安装logstash+kibana+elasticsearch+redis搭建集中式日志分析平台 2014-01-16 19:40:57| 分类: logstash | 标签:logstash ...
- Solidworks如何打开swb文件
把swb文件拖放到Solidworks里面,会弹出窗口选择一个文件夹 随后会自动生成对应的文件,装配体
- 保存html代码
function svcode(F) { if (document.all) { var F = $id(F); var E = window.open("", "_bl ...