pt-mext
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY