本文主要介绍使用Anemometer基于pt-query-digest将MySQL慢查询可视化,因为网上资料相对较少,且都是英文的,遇到报错也没有相关的参考资料,因此写此文。


欢迎转载,请注明作者、出处。

作者:张正
blog:http://space.itpub.net/26355921 
QQ:176036317
如有疑问,欢迎联系。

准备条件:
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
 
以及:
 

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

7.最终本地通过IP访问:
http://192.168.44.130/anemometer
 

查询后可获得慢查询日志的结果:
 

参考文章:
https://github.com/box/Anemometer

https://rtcamp.com/tutorials/mysql/slow-query-log-anemometer/

【转载】 使用Anemometer基于pt-query-digest将MySQL慢查询可视化的更多相关文章

  1. 使用Anemometer基于pt-query-digest将MySQL慢查询可视化

    最近玩MySQL,发现了一个很不错的工具,可以把MySQL慢查询可视化,方便我们去找出和分析慢询语句,搭建的步骤不多,但网上详细教程比较少,说得也不够详细,一不小心,估计得蛋痛一会,哈哈 Percon ...

  2. 十分钟部署Anemometer作为Mysql慢查询可视化系统

    前言 采用Anemometer将Mysql慢查询日志可视化,可以更便捷的查询慢查询日志,并根据时间戳进行历史查询.如下是单机版Anemometer部署的演示,实际应用中,为安全起见,建议把anemom ...

  3. 【转载】打造基于 Centos 7.X 的 spice 服务器

    [转载]打造基于 Centos 7.X 的 spice 服务器 https://segmentfault.com/a/1190000011991047

  4. (转)python 全栈开发,Day74(基于双下划线的跨表查询,聚合查询,分组查询,F查询,Q查询)

    昨日内容回顾 # 一对多的添加方式1(推荐) # book=Book.objects.create(title="水浒传",price=100,pub_date="164 ...

  5. 如何查找MySQL中查询慢的SQL语句(转载)

    转载自https://www.cnblogs.com/qmfsun/p/4844472.html 如何在mysql查找效率慢的SQL语句呢?这可能是困然很多人的一个问题,MySQL通过慢查询日志定位那 ...

  6. day056-58 django多表增加和查询基于对象和基于双下划线的多表查询聚合 分组查询 自定义标签过滤器 外部调用django环境 事务和锁

    一.多表的创建 from django.db import models # Create your models here. class Author(models.Model): id = mod ...

  7. python 全栈开发,Day74(基于双下划线的跨表查询,聚合查询,分组查询,F查询,Q查询)

    昨日内容回顾 # 一对多的添加方式1(推荐) # book=Book.objects.create(title="水浒传",price=100,pub_date="164 ...

  8. 032:基于Consul和MGR的MySQL高可用架构

    目录 一.Consul 1.Consul简介 2.准备环境 3.Consul 安装 4.Consul配置文件 5.Consul 服务检查脚本 6.Consul启动 二.MGR搭建 1.MGR配置 2. ...

  9. Django基础(5) ----基于双下划线的跨表查询,聚合查询,分组查询,F查询,Q查询

    一.基于双下划线的跨表查询 Django 还提供了一种直观而高效的方式在查询(lookups)中表示关联关系,它能自动确认 SQL JOIN 联系.要做跨关系查询,就使用两个下划线来链接模型(mode ...

随机推荐

  1. 监控服务器JVM内存运行

    使用jdk的jconsole进行监控jmx 首先,设置监控对象的端口   配置 catalina.sh #vi /usr/tomcat/bin/catalina.sh 注: /usr/tomcat/b ...

  2. mysql 中浮点型与定点型记录

    为了能够引起大家的重视,在介绍浮点数与定点数以前先让大家看一个例子: mysql> CREATE TABLE test (c1 float(10,2),c2 decimal(10,2)); Qu ...

  3. java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext

    ***************************错误提示************************************************ SEVERE: A child cont ...

  4. 把txt文件中的json字符串写到plist文件中

    - (void)json2Plist { NSString *filePath = [self applicationDocumentsDirectoryFileName:@"json&qu ...

  5. Linux 网卡驱动设备程序设计(1)

    一.网卡驱动架构分析 1. Linux 网络子系统 #系统调用接口层 为应用程序提供访问网络子系统的统一方法. #协议无关层 提供通用的方法来使用传输层协议. #协议栈的实现 实现具体的网络协议 #设 ...

  6. vs2013发布时: sgen.exe 已退出 代码为 1

    出现这个错的时候,有查网上的.自己也亲试了一下,注意两个地方就行. 红色框里设成这样的值就OK了!

  7. ASP.Net上传中文文件乱码

    只要在Head中添加即可解决:<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />

  8. How Old Are You?

    今天要分享的是一个测年龄的小应用,就类似是http://how-old.net官网测年龄的功能一样,我的也是这样一个功能,细节捕获当然没有how-old多啦,不过这些主要是基于一个第三方的jar包,我 ...

  9. MVC常用 ActionResult

    1.EmptyResult 2.ContentResult 3.FileResult 4.JavaScriptResult 5.JsonResult 6.HttpStatusCodeResult 7. ...

  10. dicom格式文件 界定标识符的处理

    转自:http://www.cnblogs.com/assassinx/archive/2013/05/18/3084854.html 说到底无非几个事情 :1传输语法确定 2数据元素读取 3 7fe ...