zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Linux 命令汇总总结相关
    数据结构---python---表
    python-----Queue模块
    再看python多线程------threading模块
    <转> Struct 和 Union区别 以及 对内存对齐方式的说明
    python装饰器
    HTTP权威指南----缓存
    HTTP权威指南----连接管理
    以python理解Linux的IO多路复用,select、poll、epoll
    <转载> pycharm快捷键及一些常用设置
  • 原文地址:https://www.cnblogs.com/ivictor/p/6020418.html
Copyright © 2011-2022 走看看