MySQL · 2016-11-08 3

Percona-Toolkit系列之pt-mext 监控MySQL状态的利器

介绍


在平时的生产环境中,我们经常会碰到监控MySQL的各个状态值的一个变化趋势,然后就会自己写个脚本,将status快照保存到文本中。当我们去分析的时候,需要自己去比较差值,是一件比较麻烦的时候,虽然可以用mysqladmin extended-status -r 得到相对值,但是如果想得到那个时间点status的值,就比较麻烦,这时候pt-mext就登场了。

使用


pt-mext 使用非常简单,主要有两种使用方法:

一、直接获取mysqladmin ext的输出

shell > pt-mext -r -- mysqladmin ext -i10 -c5  > mysql_status.log
shell > more mysql_status.log 
Aborted_clients                               1           0           0           0
Aborted_connects                              0           0           0           0
Binlog_cache_disk_use                       440           0           0           0
Binlog_cache_use                            442           0           0           0
Binlog_stmt_cache_disk_use                    0           0           0           0
Binlog_stmt_cache_use                         6           0           0           0
Bytes_received                        195023827          35          35          35
Bytes_sent                               253581        9938        9938        9938
....

-i10  : 采集间隔

-c5:采集次数

-r  :相对的

这会详细的列出每个变量在这一阶段的一个初始值(第一列)以及每两个采样点的差异值。

上面例子中Bytes_received 中的195023827 是采样的初始值,后面的35是每两个采样点的差异值。

 

二、获取status快照进行分析

shell > mysqladmin ext -i10 -c5 > mysql_status.log

shell > pt-mext  -r --  cat mysql_status.log  

出现的结果和上面类似

这里可以结合pt-aligh 工具进行对其

shell > pt-mext  -r --  cat mysql_status.log  | pt-align

该种方法可以自己先将status的值进行采样,然后进行分析。

 


分析发现pt-mext 对最后一个采样不进行分析,不知道是不是算一个小BUG。

官方中有如下解释:

When it finds a blank line, it assumes that a new sample of SHOW GLOBAL STATUS is starting, and it creates a new temporary
file.

笔者测试如下

shell > echo "" >>  mysql_status.log
shell > pt-mext -r --  cat mysql_status.log | grep Bytes_received 
Bytes_received                        195023827          35          35          35          35

就出现了第五次采样和第四次采样的差异值。