Skip to content

dinghunter/myawr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

 1.What is myawr

Myawr is a tool for collecting and analyzing performance data for MySQL database (including os info ,mysql status info and Slow Query Log  all of details). The idea comes from Oracle awr. Myawr periodic collect data and save to the database as snapshots. Myawr was designed as CS architecture.Myawr depends on (but not necessary) performance schema of MySQL database. Myawr consists of two parts:

myawr.pl——–a perl script for collecting mysql performance data
myawrrpt.pl—–a perl script for analyzing mysql performance data

Myawr relies on the Percona Toolkit to do the slow query log collection. Specifically you can run pt-query-digest. To parse your slow logs and insert them into your server database for reporting and analyzing.

Thanks to orzdba.pl ([email protected]).

 

If you like to read pdf,pls click myawr_reference_guid

 

 2.Myawr Data Model

myawr db include tables list:
mysql> show tables;
+———————————————————-+
| Tables_in_myawr                                             |
+———————————————————-+
| myawr_cpu_info                                               |
| myawr_host                                                      |
| myawr_innodb_info                                          |
| myawr_io_info                                                  |
| myawr_isam_info                                             |
| myawr_load_info                                              |
| myawr_mysql_info                                           |
| myawr_query_review                                       |
| myawr_query_review_history                          |
| myawr_snapshot                                             |
| myawr_snapshot_events_waits_summary_by_instance |
| myawr_snapshot_events_waits_summary_global_by_event_name |
| myawr_snapshot_file_summary_by_event_name |
| myawr_snapshot_file_summary_by_instance |
| myawr_swap_net_disk_info                             |
+———————————————————-+
15 rows in set (0.01 sec)

some key tables:
myawr_host– mysql instance config table
myawr_snapshot — snapshot table,exec myawr.pl a time as a shapshot
myawr_query_review_history — The table in which to store historical values for review trend analysis about slow log.

myawr data model:
myawr_snapshot.host_id reference myawr_host.id;
myawr_query_review_history.hostid_max reference myawr_host.id;
myawr_innodb_info.(host_id,snap_id) reference myawr_snapshot.(host_id,snap_id);
myawr1

 3. Quickstart

If you are interesting to use this tool, here’s what you need:

1. A MySQL database to store snapshot data and slow log analysis data .
2. pt-query-digest by percona
3. A MySQL server(version 5.5) with perl-DBD-mysql
4. slow query logs named like slow_20130521.log,you can switch slow logs every day.

3.1 install db
Connect to the MySQL database where store the performance data and issue the following command in myawr.sql:

CREATE DATABASE `myawr` DEFAULT CHARACTER SET utf8;
grant all on myawr.* to ‘user’@'%’ identified by “111111″;

then create tables in db myawr.


3.2 initialize myawr_host

Insert a config record about your mysql instacne,just like:
INSERT INTO `myawr_host`(id,host_name,ip_addr,port,db_role,version) VALUES (6, ‘db2.11′, ’192.168.2.11′, 3306, ‘master’, ’5.5.27′);
3.3 add two jobs in crontab

* * * * * perl /data/mysql/sh/myawr.pl -u user -p 111111 -lh 192.168.2.11 -P 3306 -tu user -tp 111111 -TP 3306 -th 192.168.1.92 -n eth0 -d sdb1 -I 6 >> /data/mysql/sh/myawr_pl.log 2>&1
15 14 * * * /data/mysql/sh/pt-query-digest --user=user --password=111111 --review h=192.168.1.92,D=myawr,t=myawr_query_review --review-history h=192.168.1.92,D=myawr,t=myawr_query_review_history --no-report --limit=100\% --filter="\$event->{add_column} = length(\$event->{arg}) and \$event->{hostid}=6" /data/mysql/sh/slow_`date -d "-1 day" +"\%Y\%m\%d"`.log >> /data/mysql/sh/pt-query_run.log 2>&1

myawr.pl Parameters:
-h,–help Print Help Info.
-i,–interval Time(second) Interval(default 1).
-d,–disk Disk Info(can’t be null,default sda1).
-n,–net Net Info(default eth0).
-P,–port Port number to use for local mysql connection(default 3306).
-u,–user user name for local mysql(default user).
-p,–pswd user password for local mysql(can’t be null).
-lh,–lhost localhost(ip) for mysql where info is got(can’t be null).
-TP,–tport Port number to use formysql where info is saved (default 3306)
-tu,–tuser user name for mysql where info is saved(default user).
-tp,–pswd user password for mysql where info is saved(can’t be null).
-th,–thost host(ip) for mysql where info is saved(can’t be null).
-I,–tid db instance register id(can’t be null,Reference myawr_host.id)

pt-query-digest Parameters:
–user user name for mysql where info is saved
–password user password for mysql where info is saved
–review Store a sample of each class of query in this DSN
h host(ip) for mysql where info is saved
D database
t table name
–review-history The table in which to store historical values for review trend analysis.
h host(ip) for mysql where info is saved
D database
t table name
$event->{hostid}=6 db instance register id(Reference myawr_host.id)

The pt-query-digest only support mechanism for switching a slow log file every day just now, named like slow_20130521.log(slow_date -d “-1 day” +”%Y%m%d”.log)

 4. Dependencies

perl-DBD-mysql
you can install it two way:
yum install perl-DBD-MySQL
or install manually like :
mkdir /tmp/mysqldbd-install
cp /usr/lib64/mysql/*.a /tmp/mysqldbd-install
perl Makefile.PL –libs=”-L/tmp/mysqldbd-install -lmysqlclient”
make
make test
make install

 5. Mysql WorkLoad Report

We can use myawrrpt.pl to generate mysql workload report.You can execute the script on MySQL database machine where store the performance data,but perl-DBD-MySQL is required.We also can execute the script in any linux machine with perl-DBD-MySQL installed.

You can execute it for help Info:
perl myawrrpt.pl -h

Info :
Created By noodba (www.noodba.com).
References: Oracle awr
Usage :
Command line options :

-h,–help Print Help Info.

-P,–port Port number to use for local mysql connection(default 3306).
-u,–user user name for local mysql(default user).
-p,–pswd user password for local mysql(can’t be null).
-lh,–lhost localhost(ip) for mysql where info is got(can’t be null).

-I,–tid db instance register id(can’t be null,Ref myawr_host.id)

Sample :
shell> perl myawrrpt.pl -p 111111 -lh 192.168.1.111 -I 11
============================================================================

Let use to generate mysql (db2.11,instance id = 6) workload report:
perl myawrrpt.pl -u user -p 111111 -P 3306 -lh 192.168.1.92 -I 6
===================================================
| Welcome to use the myawrrpt tool !
| Date: 2013-05-22
|
| Hostname is: db2.11
| Ip addr is: 192.168.2.11
| Port is: 3306
| Db role is: master
|Server version is: 5.5.27
| Uptime is: 0y 2m 2d 7h 55mi 33s
|
| Min snap_id is: 1
| Min snap_time is: 2013-05-21 14:12:02
| Max snap_id is: 1147
| Max snap_time is: 2013-05-22 09:29:02
| snap interval is: 60s
===================================================

Listing the last 2 days Snapshots
———————————
snap_id: 19 snap_time : 2013-05-21 14:30:02
snap_id: 38 snap_time : 2013-05-21 14:49:02
snap_id: 57 snap_time : 2013-05-21 15:08:02
snap_id: 76 snap_time : 2013-05-21 15:27:02
snap_id: 95 snap_time : 2013-05-21 15:46:02

……………………………………………..

snap_id: 1102 snap_time : 2013-05-22 08:44:02
snap_id: 1121 snap_time : 2013-05-22 09:03:02
snap_id: 1140 snap_time : 2013-05-22 09:22:02
snap_id: 1147 snap_time : 2013-05-22 09:29:02

Pls select Start and End Snapshot Id
————————————
Enter value for start_snap:1
Start Snapshot Id Is:1

Enter value for end_snap:589
End Snapshot Id Is:589

Set the Report Name
——————-

Enter value for report_name:myawr.html

Using the report name :myawr.html

Generating the mysql report for this analysis …
Generate the mysql report Successfully.

[mysql@test2 myawr]$ ls -al
total 976
drwxrwxr-x 2 mysql mysql 4096 May 22 09:30 .
drwx—— 19 mysql mysql 4096 May 13 10:42 ..
-rw-rw-r– 1 mysql mysql 73074 May 22 09:30 myawr.html
-rw-rw-r– 1 mysql mysql 53621 May 11 16:23 myawrrpt.pl

Mysql WorkLoad Report
Let me show some pictures which come from my test db report:
myawr2  myawr3
myawr4

For detail report ,pls click myawr.html

6. Contact me

Any questions,pls contact me freely. 

EMAIL: [email protected]
Q Q : 570182914
Phone: (+86)13817963180

 

About

awr of MySQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Perl 100.0%