MySQL实时性能监控工具doDBA tools

doDBA tools是什么?

doDBA tools是一个基于控制台的远程监控工具,它不需要在本地/远程系统上安装任何软件,它可以实时收集操作系统、MySQL、InnoDB的实时性能状态数据,并可以生成Doing日志文件,来帮助你快速了解/优化系统及MySQL数据库。

特点:

  • golang语言开发。
  • 可收集Linux、MySQL相关性能数据。
  • 可本地或远程收集,可多台。
  • 提供类似Linux top的mytop的功能。
  • 基于并发生成Doing日志,还原现场。
  • 可记录到日志文件。

doDBA tools工作原理

远程收集系统信息是通过ssh(需提供用户名和密码)的方式连接到远程服务器上收集,收集的方法都是通过读取Linux的proc下的等meminfo,diskstats,uptime,net,vmstat ,cpuinfo ,loadavg等文件,这和pmm,zabbix收集方式一致。

远程收集MySQL信息是通过 MySQL tcp连接到MySQL数据库上收集,只需要授予连接用户PROCESS、SELECT权限即可。

系统信息和MySQL信息的收集可以分离,如果只想收集系统信息,只需要提供系统用户名密码即可,如果只收集MySQL可以只提供MySQL连接信息,如果是rds用户,可以使用-rds参数,在使用mytop时会自动忽略系统信息的收集。

如何使用doDBA?

Github主页:https://github.com/dblucyne/dodba_tools
wget https://raw.githubusercontent.com/dblucyne/dodba_tools/master/doDBA --no-check-certificate
wget https://raw.githubusercontent.com/dblucyne/dodba_tools/master/doDBA.conf --no-check-certificate
chmod +x doDBA

下载下来就可以直接使用,不依赖于任何环境。但可以在doDBA.conf配置文件中先把需要设置的信息填写好。

 

{
  "Host":"",
  "Huser": "root",
  "Hport": "22",
  "Hpwd":  "",
  "Muser": "root",
  "Mpwd":  "123456",
  "Mport":"3306"
}

  

使用帮助:

 

$ ./doDBA --help
Usage of ./doDBA:
 -c string
 configuration file. (default "doDBA.conf")
 -h string
 Connect to host/IP.
 -hP string
 Connect host port. (default "22")
 -help
 Display this help.
 -hp string
 Connect host password.
 -hu string
 Connect host user. (default "root")
 -i duration
 refresh interval in seconds. (default 1ns)
 -innodb
 Print innodb info.
 -log
 Print to file by day.
 -mP string
 Connect mysql port. (default "3306")
 -mp string
 Connect mysql password.
 -mu string
 Connect mysql user.
 -myall
 Print system and mysql info.
 -mysql
 Print mysql info.
 -mytop
 Print mysql prcesslist info , like top.
 -nocolor
 Print nocolor.
 -rds
 Ignore system info.
 -sys
 Print system info.
 -t int
 mysql trace on Threads_running. (default 50)

  

使用实例

1. 收集Linux性能数据

 

$ ./doDBA -h=127.0.0.1 -sys

DoDBA tools on host 127.0.0.1
---------+----load--avg----+-----cpu-usage-----+--swap--+----net----+-----------IO-----------
time     |   1m    5m   10m| usr  sys  iow  ide|  si  so| recv  send|   r/s   w/s  rb/s  wb/s
---------+-----------------+-------------------+--------+-----------+------------------------
19:23:51 | 1.35  0.72  0.41| 4.2  3.0  3.2 89.6|   0   0|16384.0P16384.0P|    48  2396  768K 69.2M
19:23:52 | 1.35  0.72  0.41| 4.8  2.9  3.1 89.2|   0   0|16384.0P16384.0P|    68  2502  1.1M 71.1M

  

 

2. 收集MySQL性能数据

 

$ ./doDBA -h=127.0.0.1 -mysql

DoDBA tools on host 127.0.0.1
---------+-------mysql-status-------+-----threads-----+-----slow-----+---bytes---+---------locks----------
time     |   QPS  TPS  ins  upd  del| run  con cre cac| sql  tmp Dtmp| recv  send| lockI lockW openT openF
---------+--------------------------+-----------------+--------------+-----------+------------------------
19:27:32 |    25   11    0   11    0|   3   99   0   6|   0    1    0|   5K   37K|    36     0   538    93
19:27:33 |    37  152   13    5  134|   3   99   0   6|   0    5    1|  35K  396K|   216     0   538    93
19:27:34 |    39   60    8    8   44|   4   99   0   6|   0    5    0|  26K  220K|   115     0   538    93

 

3. 收集InnoDB性能数据

 

$ ./doDBA -h=127.0.0.1 -innodb

DoDBA tools on host 127.0.0.1
---------+------innodb--rows-----+---------innodb--pages--------+-------innodb--data-------+--innodb-log--
time     |    read  ins  upd  del|    data    free   dirty flush|reads writes  read written|fsyncs written
---------+-----------------------+------------------------------+--------------------------+--------------
19:30:00 |    4741  458   32    0|  350602    8195   18869   125|    0    141    0K    4.0M|     1     66K
19:30:01 |     106  521    3    0|  350602    8195   18858   137|    0    151    0K    4.4M|     1     72K
19:30:02 |    7982  406   40    2|  350603    8194   18860   160|    0    202    0K    5.1M|     3     84K

  

4. 收集MySQL及Linux性能数据
$ ./doDBA -h 127.0.0.1 -myall
5. mytop –like linux top
$ ./doDBA -h 127.0.0.1 -mytop

DoDBA tools -19:32:36 on host 127.0.0.1 UP 61 days  Load: 0.64 0.75 0.63 
CPU: 1.99% user, 2.84% sys, 0.00% nice, 0.28% iowait, 94.89% idle
Mem:  23.3G total, 23.0G used, 317.6M free, 0K buffers 
Swap:  24.0G total, 0K used, 24.0G free, 13.2G Cached 
MySQL: 16 QPS, 20 TPS, 0 slowSQL, 2 run

         ID          USER      IP/HOST          DB     Time           State                            SQL
         --          ----      -------          --     ----           -----                            ---
    2495440        zabbix    127.0.0.1                    0            init          show full processlist

  

6. 借助Shell收集多台
$ cat ip.txt
10.1.x.x1
10.1.x.x2

  

Shell

 

$ cat ip.txt | 
while read ip; do 
 echo $ip;
 ./doDBA -h=$ip -mysql -log </dev/null & 
done
7. 收集到日志文件

 

 

$ ./doDBA -h=127.0.0.1 -mysql -log

$ cat 127001_dodba_mysql_20161219.log 
DoDBA tools on host 127.0.0.1
---------+-------mysql-status-------+-----threads-----+-----slow-----+---bytes---+---------locks----------
time     |   QPS  TPS  ins  upd  del| run  con cre cac| sql  tmp Dtmp| recv  send| lockI lockW openT openF
---------+--------------------------+-----------------+--------------+-----------+------------------------
19:35:30 |    23   15   10    5    0|   3   98   0   7|   0    2    1|   9K  8.0M|    43     0   538    95
19:35:31 |    53   19    5   14    0|   2   98   0   7|   0    3    0|  38K  1.7M|    86     0   538    93

  

 

8. 开启Doing功能

使用【-t】参数可以基于Threads_running的数量设置阈值,设置后可记录「processlist,engine innodb status」信息到dodba.log日志中,–重现现场。

 

$ ./doDBA -h=127.0.0.1 -mysql -t=3

  

 

9. 查看Doing日志

 

 

$ tail -f dodba.log
2016/12/19 19:51:52 ----------------processlist---------------
ID:2314306
User:zabbix
Host:localhost
DB:zabbix
Command:Query
Time:0
State:update
Info:insert into history_uint (itemid,clock,ns,value) values (35632,1482148312,240404292,274)