Linux命令之mpstat日常使用

想看操作系统每颗CPU的使用情况,在网上查找的时候发现了这个命令,于是写这篇文章就当学习记录,方便以后用到时查看。

命令概述:

mpstat - Report processors related statistics。这是摘抄Linux man手册的内容,这个命令是干啥的从这一句解释来看简洁明了。翻译成汉语,就是一台服务器上的所有处理器(通常说的CPU)相关的统计信息。这个命令可以看到每颗CPU的使用情况,这正好能满足我的需求。

语法解释:

mpstat [ -A ] [ -u ] [ -V ] [ -I { SUM | CPU | SCPU | ALL } ] [ -P { cpu [,...] | ON | ALL } ] [ interval [ count ] ]

该命令使用也比较简单,相关的参数比较少,以下分别对每个参数做详细说明: 

mpstat相关参数说明
参数值说明
-A相当于指定了-u -I ALL -P ALL
-u效果跟直接执行mpstat一样,显示CPU的平均使用信息
-V输出版本号
-I统计中断的信息
-P统计每颗CPU的使用状态

interval

结果隔几秒输出一次
count结果输出的总数


常用命令

以下命令表示每5秒输出所有CPU的使用情况,一共输出3次。

[root@dr19crac1 ~]# mpstat -P ALL 5 3 
Linux 3.10.0-957.el7.x86_64 (dr19crac1)         01/09/2024      _x86_64_        (4 CPU)

11:32:43 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
11:32:48 AM  all    4.79    0.00    3.42    0.11    0.00    0.16    0.00    0.00    0.00   91.53
11:32:48 AM    0    5.70    0.00    3.59    0.21    0.00    0.21    0.00    0.00    0.00   90.30
11:32:48 AM    1    4.46    0.00    4.25    0.21    0.00    0.21    0.00    0.00    0.00   90.87
11:32:48 AM    2    5.25    0.00    2.73    0.21    0.00    0.21    0.00    0.00    0.00   91.60
11:32:48 AM    3    3.97    0.00    2.72    0.00    0.00    0.00    0.00    0.00    0.00   93.31
^C

Average:     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
Average:     all    4.79    0.00    3.42    0.11    0.00    0.16    0.00    0.00    0.00   91.53
Average:       0    5.70    0.00    3.59    0.21    0.00    0.21    0.00    0.00    0.00   90.30
Average:       1    4.46    0.00    4.25    0.21    0.00    0.21    0.00    0.00    0.00   90.87
Average:       2    5.25    0.00    2.73    0.21    0.00    0.21    0.00    0.00    0.00   91.60
Average:       3    3.97    0.00    2.72    0.00    0.00    0.00    0.00    0.00    0.00   93.31

输出的结果中,%usr,%sys,%iowait,%idle都是一些常见的指标,此处不做多余介绍。

mpstat指标说明
名称定义个人理解
%niceShow the percentage of CPU utilization that occurred while executing at the user level with nice priority.展示设定用户优先级的CPU使用率
%irqShow the percentage of time spent by the CPU or CPUs to service hardware interrupts.展示硬中断占用CPU的百分比
%softShow the percentage of time spent by the CPU or CPUs to service software interrupts.展示软中断占用CPU的百分比
%stealShow the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.展示虚拟服务器服务于其他虚拟处理器时花费的非自愿等待占用CPU的百分比
%guestShow the percentage of time spent by the CPU or CPUs to run a virtual processor.显示CPU运行虚拟处理器所花费的时间百分比
%gniceShow the percentage of time spent by the CPU or CPUs to run a niced guest.显示CPU运行nice客户所花费的时间百分比

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lglovegq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值