linux mpstat命令

8次阅读

共计 3328 个字符,预计需要花费 9 分钟才能阅读完成。

1. mpstat 命令
1.1 命令格式
mpstat [-A] [-u] [-V] [-I { SUM | CPU | SCPU | ALL} ] [-P { cpu [,…] | ON | ALL } ] [interval [ count] ]
OPTIONS:-A: 等同于 -u -I ALL -P ALL-I: 可以指定 SUM CPU SCPU ALL 四个参数,SUM 表示每个处理器的中断总数,CPU 表示每个核的每秒中断数量,SCPU 表示每个核每秒的软中断数量,内核版本在 2.6.31 之后才支持。-P: 统计的 CPU 编号,一般用 ALL-u: 输出列的信息 -V: 查看工具版本号
2. 使用
2.1 每隔 1s 输出所有 cpu 的使用情况
$ mpstat -P ALL 1
Linux 3.10.0-693.el7.x86_64 (zhanghao) 2019 年 02 月 26 日 _x86_64_ (2 CPU)

12 时 42 分 03 秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
12 时 42 分 04 秒 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12 时 42 分 04 秒 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12 时 42 分 04 秒 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

12 时 42 分 04 秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
12 时 42 分 05 秒 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12 时 42 分 05 秒 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12 时 42 分 05 秒 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

12 时 42 分 05 秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
12 时 42 分 06 秒 all 0.00 0.00 0.00 0.50 0.00 0.00 0.00 0.00 0.00 99.50
12 时 42 分 06 秒 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12 时 42 分 06 秒 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

12 时 42 分 06 秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
12 时 42 分 07 秒 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12 时 42 分 07 秒 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12 时 42 分 07 秒 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

12 时 42 分 07 秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
12 时 42 分 08 秒 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12 时 42 分 08 秒 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12 时 42 分 08 秒 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
字段分析: CPU: 每个 CPU 的 process id%usr: 用户态下,cpu 的利用率 %nice: 具有 nice 优先级的用户下,CPU 的使用率 %sys: 显示在 kernel 内核态执行时发生的 CPU 利用率百分比。这不包括维护硬件和软件中断所花费的时间。%iowait: 显示系统有未完成的磁盘 I / O 请求时,CPU 或 CPU 处于空闲状态的时间百分比 %irq: 系统服务于硬中断的时间开销的百分比 %soft: 系统服务于软中断开销的时间开销百分比 %steal: 显示虚拟 CPU 或 CPU 在虚拟机监控程序为另一个虚拟处理器提供服务时被迫等待所花费的时间百分比 %guest: CPU 处理虚拟进程的花费的时间开销 %idel: CPU 空闲百分比
2.2 查看软中断统计信息
$ mpstat -I SCPU 1
Linux 3.10.0-693.el7.x86_64 (zhanghao) 2019 年 02 月 26 日 _x86_64_ (2 CPU)

15 时 23 分 07 秒 CPU HI/s TIMER/s NET_TX/s NET_RX/s BLOCK/s BLOCK_IOPOLL/s TASKLET/s SCHED/s HRTIMER/s RCU/s
15 时 23 分 08 秒 0 0.00 5.00 0.00 0.00 0.00 0.00 0.00 2.00 0.00 4.00
15 时 23 分 08 秒 1 0.00 28.00 0.00 5.00 0.00 0.00 0.00 24.00 0.00 3.00
15 时 23 分 09 秒 0 0.00 6.00 0.00 0.00 2.00 0.00 0.00 3.00 0.00 5.00
15 时 23 分 09 秒 1 0.00 26.00 0.00 70.00 0.00 0.00 0.00 24.00 0.00 2.00
15 时 23 分 10 秒 0 0.00 16.00 0.00 0.00 0.00 0.00 0.00 12.00 0.00 3.00
15 时 23 分 10 秒 1 0.00 13.00 0.00 6.00 0.00 0.00 0.00 13.00 0.00 1.00
15 时 23 分 11 秒 0 0.00 18.00 0.00 0.00 2.00 0.00 0.00 14.00 0.00 3.00
15 时 23 分 11 秒 1 0.00 12.00 0.00 5.00 0.00 0.00 0.00 10.00 0.00 1.00
15 时 23 分 12 秒 0 0.00 8.00 0.00 0.00 0.00 0.00 0.00 4.00 0.00 3.00
15 时 23 分 12 秒 1 0.00 30.00 0.00 40.00 0.00 0.00 0.00 19.00 0.00 4.00
15 时 23 分 13 秒 0 0.00 7.00 0.00 0.00 2.00 0.00 0.00 3.00 0.00 3.00
15 时 23 分 13 秒 1 0.00 23.00 0.00 7.00 0.00 0.00 0.00 22.00 0.00 1.00
15 时 23 分 14 秒 0 0.00 11.00 0.00 0.00 0.00 0.00 0.00 7.00 0.00 6.00
15 时 23 分 14 秒 1 0.00 30.00 0.00 12.00 1.00 0.00 0.00 25.00 0.00 8.00
15 时 23 分 15 秒 0 0.00 9.00 0.00 0.00 2.00 0.00 0.00 6.00 0.00 6.00
15 时 23 分 15 秒 1 0.00 31.00 0.00 7.00 0.00 0.00 0.00 24.00 0.00 5.00
15 时 23 分 16 秒 0 0.00 8.00 0.00 0.00 0.00 0.00 0.00 4.00 0.00 6.00
15 时 23 分 16 秒 1 0.00 25.00 0.00 6.00 0.00 0.00 0.00 22.00 0.00 3.00
15 时 23 分 17 秒 0 0.00 10.00 0.00 0.00 2.00 0.00 0.00 6.00 0.00 3.00
15 时 23 分 17 秒 1 0.00 24.00 0.00 7.00 0.00 0.00 0.00 23.00 0.00 1.00
2.3 每隔 2s 输出一次,输出 3 次
$ mpstat 2 3
Linux 3.10.0-693.el7.x86_64 (zhanghao) 2019 年 02 月 27 日 _x86_64_ (2 CPU)

02 时 13 分 29 秒 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
02 时 13 分 31 秒 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
02 时 13 分 33 秒 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
02 时 13 分 35 秒 all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
平均时间: all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

正文完
 0