日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

發布時間:2024/8/26 数据库 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用Anemometer基于pt-query-digest将MySQL慢查询可视化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本文主要介紹使用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慢查询可视化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。