暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

工具|mpstat 查看cpu 负载信息

yangyidba 2022-11-22
1110

mpstat是Multiprocessor Statistics的缩写,是实时系统监控工具。基于 proc/stat 的数据来 展示 CPU的统计信息。在多核系统中,该命令不但能查看所有CPU的信息,而且能够查看特定CPU的信息。mpstat 最大的特点是:可以查看多核cpu中每个计算核心的统计数据;而类似工具vmstat只能查看系统整体cpu情况。

说明

mpstat命令 指令主要用于多CPU环境下,它显示各个可用CPU的状态系你想。这些信息存放在/proc/stat文件中。在多CPUs系统里,其不但能查看所有CPU的平均状况信息,而且能够查看特定CPU的信息。

语法

mpstat [-P {|ALL}] [internal [count]]
参数 解释
-P {|ALL} 表示监控哪个CPU, cpu在[0,cpu个数-1]中取值
internal 相邻的两次采样的间隔时间、
count 采样的次数,count只能和delay一起使用
当没有参数时,mpstat则显示系统启动以后所有信息的平均值。

具体使用

当mpstat不带参数时,输出为从系统启动以来的平均值,每隔两秒输出一次统计数据。

[root@db1 ~]# mpstat
Linux 4.18.0-193.28.1.el7.aarch64 (db1)  2022年11月21日  _aarch64_ (64 CPU)

23时06分50秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
23时06分50秒  all    3.57    0.00    0.78    0.10    0.00    0.61    0.00    0.00    0.00   94.94

输出的结果字段的含义如下

%user      在internal时间段里,用户态的CPU时间(%),不包含nice值为负进程  (usr/total)*100
%nice      在internal时间段里,nice值为负进程的CPU时间(%)   (nice/total)*100
%sys       在internal时间段里,内核时间(%)       (system/total)*100
%iowait    在internal时间段里,硬盘IO等待时间(%) (iowait/total)*100
%irq       在internal时间段里,硬中断时间(%)     (irq/total)*100
%soft      在internal时间段里,软中断时间(%)     (softirq/total)*100
%idle      在internal时间段里,CPU除去等待磁盘IO操作外的因为任何原因而空闲的时间闲置时间(%) (idle/total)*100

下面的命令可以每2秒产生所有CPU的统计数据报告,一共产生3次的信息,然后再给出这3个interval的平均信息。默认时,输出是按照CPU 号排序。第一个行给出了从系统引导以来的所有活跃数据。接下来每行对应一个处理器的活跃状态。。

[root@db1 ~]# mpstat -P ALL 2 3
Linux 4.18.0-193.28.1.el7.aarch64 (db1)  2022年11月21日  _aarch64_ (64 CPU)

23时16分36秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
23时16分38秒  all   56.57    0.12   13.07    0.09    0.00   28.81    0.00    0.00    0.00    1.35
23时16分38秒    0   48.50    0.00    9.00    0.00    0.00   41.50    0.00    0.00    0.00    1.00
23时16分38秒    1   79.40    0.00   18.59    0.00    0.00    0.00    0.00    0.00    0.00    2.01
23时16分38秒    2   38.00    0.00    6.00    0.00    0.00   55.00    0.00    0.00    0.00    1.00
23时16分38秒    3   80.60    0.00   17.91    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒    4   32.00    0.00    9.00    0.00    0.00   58.00    0.00    0.00    0.00    1.00
23时16分38秒    5   79.10    0.00   19.40    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒    6   18.00    0.00    6.00    0.00    0.00   75.00    0.00    0.00    0.00    1.00
23时16分38秒    7   86.57    0.00   11.94    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒    8   25.00    0.00    6.50    0.00    0.00   67.50    0.00    0.00    0.00    1.00
23时16分38秒    9   75.74    0.00   22.28    0.00    0.00    0.00    0.00    0.00    0.00    1.98
23时16分38秒   10   24.50    0.00    8.50    0.00    0.00   66.00    0.00    0.00    0.00    1.00
23时16分38秒   11   79.50    0.00   19.00    0.00    0.00    0.00    0.00    0.00    0.00    1.50
23时16分38秒   12   26.50    0.00    6.50    0.00    0.00   66.00    0.00    0.00    0.00    1.00
23时16分38秒   13   75.74    0.00   22.28    0.00    0.00    0.00    0.00    0.00    0.00    1.98
23时16分38秒   14   30.85    0.00    6.47    0.00    0.00   61.19    0.00    0.00    0.00    1.49
23时16分38秒   15   81.82    0.00   16.67    0.00    0.00    0.00    0.00    0.00    0.00    1.52
23时16分38秒   16   27.00    0.00   10.50    0.00    0.00   61.50    0.00    0.00    0.00    1.00
23时16分38秒   17   78.50    0.00   20.50    0.00    0.00    0.00    0.00    0.00    0.00    1.00
23时16分38秒   18   14.00    0.00    3.50    0.00    0.00   81.50    0.00    0.00    0.00    1.00
23时16分38秒   19   82.59    0.00   16.42    0.00    0.00    0.00    0.00    0.00    0.00    1.00
23时16分38秒   20   18.50    0.00    5.00    0.00    0.00   75.50    0.00    0.00    0.00    1.00
23时16分38秒   21   81.50    0.00   17.50    0.00    0.00    0.00    0.00    0.00    0.00    1.00
23时16分38秒   22   25.87    0.00    4.48    0.00    0.00   68.16    0.00    0.00    0.00    1.49
23时16分38秒   23   82.09    0.00   16.42    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒   24   31.00    0.00    6.50    0.00    0.00   61.50    0.00    0.00    0.00    1.00
23时16分38秒   25   81.09    0.00   17.41    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒   26   23.50    0.00    7.00    0.00    0.00   68.50    0.00    0.00    0.00    1.00
23时16分38秒   27   83.08    0.00   15.42    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒   28   22.00    0.00    6.00    0.00    0.00   71.00    0.00    0.00    0.00    1.00
23时16分38秒   29   81.09    0.00   17.41    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒   30   27.86    0.00    7.46    0.00    0.00   63.18    0.00    0.00    0.00    1.49
23时16分38秒   31   80.50    0.00   18.00    0.00    0.00    0.00    0.00    0.00    0.00    1.50
23时16分38秒   32   30.85    0.00    5.97    0.50    0.00   61.69    0.00    0.00    0.00    1.00
23时16分38秒   33   84.65    0.00   13.37    0.00    0.00    0.00    0.00    0.00    0.00    1.98
23时16分38秒   34   21.00    0.00    9.00    0.00    0.00   69.00    0.00    0.00    0.00    1.00
23时16分38秒   35   78.89    0.00   18.59    0.50    0.00    0.00    0.00    0.00    0.00    2.01
23时16分38秒   36   23.00    0.00    9.50    0.00    0.00   66.50    0.00    0.00    0.00    1.00
23时16分38秒   37   71.43    0.00   26.11    0.99    0.00    0.00    0.00    0.00    0.00    1.48
23时16分38秒   38   25.63    0.00    9.55    0.00    0.00   64.32    0.00    0.00    0.00    0.50
23时16分38秒   39   72.14    2.99   22.39    0.50    0.00    0.00    0.00    0.00    0.00    1.99
23时16分38秒   40   29.00    0.00    8.00    0.00    0.00   62.00    0.00    0.00    0.00    1.00
23时16分38秒   41   71.57    0.00   23.04    2.94    0.00    0.00    0.00    0.00    0.00    2.45
23时16分38秒   42   24.50    0.00    6.50    0.00    0.00   68.00    0.00    0.00    0.00    1.00
23时16分38秒   43   82.09    0.00   15.92    0.00    0.00    0.00    0.00    0.00    0.00    1.99
23时16分38秒   44   39.50    0.00   10.00    0.00    0.00   49.50    0.00    0.00    0.00    1.00
23时16分38秒   45   85.50    0.00   13.00    0.00    0.00    0.00    0.00    0.00    0.00    1.50
23时16分38秒   46   39.00    0.00   11.50    0.00    0.00   48.50    0.00    0.00    0.00    1.00
23时16分38秒   47   79.29    0.00   19.19    0.00    0.00    0.00    0.00    0.00    0.00    1.52
23时16分38秒   48   44.00    0.00    6.00    0.00    0.00   49.00    0.00    0.00    0.00    1.00
23时16分38秒   49   80.60    0.00   17.91    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒   50   39.50    0.00    9.00    0.00    0.00   50.50    0.00    0.00    0.00    1.00
23时16分38秒   51   76.12    0.00   22.39    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒   52   56.00    0.00    7.50    0.00    0.00   35.50    0.00    0.00    0.00    1.00
23时16分38秒   53   80.10    1.49   16.92    0.00    0.00    0.00    0.00    0.00    0.00    1.49
23时16分38秒   54   75.12    0.00   10.95    0.00    0.00   12.44    0.00    0.00    0.00    1.49
23时16分38秒   55   80.90    0.00   17.09    0.00    0.00    0.00    0.00    0.00    0.00    2.01
23时16分38秒   56   56.72    0.00   14.43    0.00    0.00   27.36    0.00    0.00    0.00    1.49
23时16分38秒   57   81.59    0.00   16.42    0.00    0.00    0.00    0.00    0.00    0.00    1.99
23时16分38秒   58   34.50    0.00    6.50    0.00    0.00   58.00    0.00    0.00    0.00    1.00
23时16分38秒   59   84.92    0.00   13.57    0.00    0.00    0.00    0.00    0.00    0.00    1.51
23时16分38秒   60   50.50    0.00   11.00    0.00    0.00   37.50    0.00    0.00    0.00    1.00
23时16分38秒   61   78.00    0.00   19.50    0.00    0.00    0.00    0.00    0.00    0.00    2.50
23时16分38秒   62   42.00    0.00   12.00    0.00    0.00   45.00    0.00    0.00    0.00    1.00
23时16分38秒   63   77.61    3.48   17.41    0.00    0.00    0.00    0.00    0.00    0.00    1.49


文章转载自yangyidba,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论