溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Mysql中Anemometer怎么用

發(fā)布時間:2021-10-29 17:18:37 來源:億速云 閱讀:220 作者:小新 欄目:MySQL數(shù)據(jù)庫

這篇文章給大家分享的是有關Mysql中Anemometer怎么用的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

準備條件:
1.MySQL開啟慢查詢


2.安裝Percona Toolkit
rpm -qa|grep percona
percona-toolkit-2.2.7-1


3.下載Anemometer
官網(wǎng):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.執(zhí)行setup 腳本,創(chuàng)建用戶:
[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.將慢查詢?nèi)罩就ㄟ^pt-query-digest分析后存入數(shù)據(jù)庫中:
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


執(zhí)行這個操作后,將會把慢日志分析后存入mysql的slow_query_log數(shù)據(jù)庫。


NOTE:
記得保證相應 '用戶'@'主機' 的訪問權限




6.修改可視界面的配置信息:
cd /var/www/html/anemometer/conf
cp sample.config.inc.php config.inc.php
vi config.inc.php
 Mysql中Anemometer怎么用
以及:
 Mysql中Anemometer怎么用

NOTE:
主機名一定要修改正確,不能保留為localhost,否則會導致最終界面無法訪問。






7.最終本地通過IP訪問:
http://192.168.44.130/anemometer
 Mysql中Anemometer怎么用


查詢后可獲得慢查詢?nèi)罩镜慕Y果:
 
Mysql中Anemometer怎么用




補充:如何監(jiān)控多個數(shù)據(jù)庫

  1. [root@RZ-SI1-DB-14 conf]# ll

  2. total 40

  3. -rwxr-xr-x 1 root root 15504 Oct 12 14:51 config.inc.php                   ###新版都不需要修改里面的配置了,只需要修改下面的datasource

  4. -rwxrwxrwx 1 root root   314 Oct 12 14:54 datasource_si1.inc.php

  5. -rwxr-xr-x 1 root root   314 Oct 12 15:05 datasource_st1.inc.php         ---配置多個datasource,si1 st1 機器上分別導入install.sql  并pt-query-digest 慢日志進去

  6. -rwxrwxrwx 1 root root     0 Oct 13  2016 index.html

  7. -rwxrwxrwx 1 root root 15487 Oct 13  2016 sample.config.inc.php


[root@RZ-SI1-DB-14 conf]# more datasource_si1.inc.php 
<?php
$conf['datasources']['si1'] = array(
        'host'  => '10.38.96.132',
        'port'  => 3306,
        'db'    => 'slow_query_log',
        'user'  => 'xxxxxx',
        'password' => 'xxxxxx',
        'tables' => array(
                'global_query_review' => 'fact',
                'global_query_review_history' => 'dimension'
        ),
        'source_type' => 'slow_query_log'
);


[root@RZ-SI1-DB-14 conf]# more datasource_st1.inc.php 
<?php
$conf['datasources']['st1'] = array(
        'host'  => '10.38.96.128',
        'port'  => 3306,
        'db'    => 'slow_query_log',
        'user'  => 'xxxxxxx',
        'password' => 'xxxxxxxx',
        'tables' => array(
                'global_query_review' => 'fact',
                'global_query_review_history' => 'dimension'
        ),
        'source_type' => 'slow_query_log'
);

Mysql中Anemometer怎么用

感謝各位的閱讀!關于“Mysql中Anemometer怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI