10-minute deployment of anemometer as a MySQL slow query visualization system

Source: Internet
Author: User
Tags install perl mysql slow query log percona

Preface

Using anemometer to visualize the MySQL slow query log, you can more easily query the slow query log, and based on the time stamp of historical query. The following is a stand-alone version of the Anemometer deployment demonstration, in practice, for security reasons, it is recommended to separate the anemometer to another machine.

Working principle

Anemometer: Implementing Log Visualization

Pt-query-digest: Extracting slow query log

Environmental information

Ip Function Software information Installation path Operating system
192.168.9.11 HTTP Service httpd-2.2.15-54 Yum Default Path centos6.9
Slow query log Fetch import Pt-query-digest RPM Default Path
Slow query log cut logrotate yum Default Path
Visual display Anemometer /var/www/html

Installation steps

1. Installing Apache

Yum Install Httpd-y

2. Install the pt-query-digest and set up the crawl script

yum install perl-dbi perl-dbd-mysql perl-time-hires perl-io-socket-ssl -y# Need to install Perl-termreadkey otherwise will error wget http://pkgs.repoforge.org/perl-termreadkey/ Perl-termreadkey-2.30-1.el3.rf.x86_64.rpmrpm -ivh perl-termreadkey-2.30-1.el3.rf.x86_64.rpmwget  https://www.percona.com/downloads/percona-toolkit/2.2.20/rpm/percona-toolkit-2.2.20-1.noarch.rpmrpm  -ivh percona-toolkit-2.2.20-1.noarch.rpmvim /home/shell_script/slow_db_export.sh#!/bin/bash/ Usr/bin/pt-query-digest --user=anemometer --password=123456 --review h=192.168.9.11,d=slow _query_log,t=global_query_review --history h=192.168.9.11,d=slow_query_log,t=global_query_review_ History --no-report --limit=0% --filter= " \ $event->{bytes} = length (\ $event- >{arg})  and \ $event->{hostname}=\ "$HOSTNAME \" " /usr/local/mysql/data/mysql.slowchmod  -r 755 /home/shell_script/slow_db_export.sh

3. Install the logrotate and configure the daily cut MySQL slow query log

Yum install Logrotate-yvim/etc/logrotate.d/mysql/usr/local/mysql/data/mysql.slow {Create 660 mysql Mysqldateextnotifemptydailymaxage 60rotate 30missingokcompressolddir/usr/local/mysql/old_logpostrotate########## Run if mysqld is runningif/usr/local/mysql/bin/mysqladmin ping-h172.27.127.12-uroot-p ' hs!hs8989 '-s/usr/local/mysql/ Mysql.sock &>/dev/null; Then/usr/local/mysql/bin/mysqladmin flush-logs-h172.27.127.12-uroot-p ' hs!hs8989 '-s/usr/local/mysql/ Mysql.sockfiendscript}chmod-r 755/etc/logrotate.d/mysql

4. Put the Pt-query-digest script and the logrotate cut script into the crontab

############ #23点55分-#################### The slow query data for the day of the split import #55 * * * */home/shell_script/slow_db_export.sh############## #23点59分-Cut Slow query log ############ #59 * * * * root (/usr/sbin/logrotate-f/etc/logrotate.d/mysql)

5. Installing anemometer

Cd/var/www/htmlgit Clone https://github.com/box/Anemometer.git anemometer&&cd anemometer# CREATE table and user name # mysql-  Uroot-proot < install.sql# mysql-uroot-proot-e "grant all on slow_query_log.* to ' anemometer ' @ ' localhost ' identified By ' 123456 '; " # MYSQL-UROOT-PROOT-E "Grant SELECT On * * to ' anemometer ' @ ' localhost ' identified by ' 123456 ';" # MYSQL-UROOT-PROOT-E "flush privileges;"

6. Import the log and open the page test (http://192.168.9.11/amemometer

#执行刚刚编辑的slow_db_export. sh script./home/shell_script/slow_db_export.sh# Restart Apacheservice httpd restart

At this point, the MySQL slow query log visualization function has been realized through anemometer.


10-minute deployment of anemometer as a MySQL slow query visualization system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.