pt-mext實現的功能比較簡單,就是將mysqladmin輸出的多次迭代的相同status變量值放到同一行輸出。
參數很少,除了--help和--version外,只有一個--relative參數
short form: -r Subtract each column from the previous column.
支持兩種用法:
1. 直接對輸出進行聚合
pt-mext -r -- mysqladmin ext -i1 -c3
注意:上述命令中會有三次迭代,但只會輸出第一次的結果,第二次和第一次相差的結果。
其中,
-i, --sleep=# Execute commands repeatedly with a sleep between.
-c, --count=# Number of iterations to make. This works with -i (--sleep) only.
extended-status Gives an extended status message from the server
[root@localhost ~]# pt-mext -r -- mysqladmin ext -i1 -c3 Aborted_clients 0 0 Aborted_connects 0 0 Binlog_cache_disk_use 0 0 Binlog_cache_use 0 0 Binlog_stmt_cache_disk_use 0 0 Binlog_stmt_cache_use 0 0 Bytes_received 2243 35 Bytes_sent 158346 9246 ......
上述命令如果不加-r參數的話,則原樣輸出。
# pt-mext -- mysqladmin ext -i1 -c3
Aborted_clients 0 0 Aborted_connects 0 0 Binlog_cache_disk_use 0 0 Binlog_cache_use 0 0 Binlog_stmt_cache_disk_use 0 0 Binlog_stmt_cache_use 0 0 Bytes_received 1681 1716 Bytes_sent 102690 111935 .....
2. 對文本文件進行聚合
pt-mext -r -- cat mysqladmin-output.txt
注意:無論是否帶-r參數,最後一次的迭代結果都不會納入輸出的范圍。
關於它的原理,可參考官方文檔的說明
pt-mext executes the COMMAND you specify, and reads through the result one line at a time. It places each line into a temporary file. 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. At the end of this process, it has a number of temporary files. It joins the temporary files together side-by-side and prints the result. If --relative option is given, it first subtracts each sample from the one after it before printing results.
即每次迭代的結果都會放入到一個臨時文件中,然後對這些臨時文件進行join。
其實,該腳本的作用不限於mysqladmin的status變量值
如下所示:
# cat 4.txt
one 1 two 2 one 2 two 3 three 4 one 3 two 4
# pt-mext -- cat 4.txt
one 1 2 two 2 3