mpstat

Display the status of each available CPU

Supplementary instructions

mpstat command is mainly used in multi-CPU environments. It displays the status information of each available CPU. This information is stored in the /proc/stat file. In a multi-CPUs system, it can not only view the average status information of all CPUs, but also view the information of a specific CPU.

grammar

mpstat [options] [<interval> [<number of times>]]

Options

-P: Specify the CPU number.

Parameters

Header meaning

Example

When mpstat takes no parameters, the output is the average value since system startup.

mpstat
Linux 3.10.0-1160.71.1.el7.x86_64 (centos) 08/14/2022 _x86_64_ (4 CPU)

04:28:36 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
04:28:36 PM all 0.03 0.00 0.07 0.00 0.00 0.01 0.00 0.00 0.00 99.89

All processor statistics report generated every 2 seconds:

The following command can generate statistical data reports for all processors every 2 seconds. A total of three intervals of information are generated, and finally the average information of these three intervals is given. By default, the output is sorted by CPU number. The first row gives all processor usage over 2 seconds. Each subsequent row corresponds to a processor usage.

mpstat -P ALL 2 3
Linux 3.10.0-1160.71.1.el7.x86_64 (centos) 08/15/2022 _x86_64_ (4 CPU)

09:32:43 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
09:32:45 AM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
09:32:45 AM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
09:32:45 AM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
09:32:45 AM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
09:32:45 AM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

09:32:45 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
09:32:47 AM all 0.00 0.00 0.12 0.00 0.00 0.12 0.00 0.00 0.00 99.75
09:32:47 AM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
09:32:47 AM 1 0.00 0.00 0.50 0.00 0.00 0.00 0.00 0.00 0.00 99.50
09:32:47 AM 2 0.00 0.00 0.00 0.00 0.00 0.50 0.00 0.00 0.00 99.50
09:32:47 AM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

09:32:47 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
09:32:49 AM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
09:32:49 AM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
09:32:49 AM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
09:32:49 AM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
09:32:49 AM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
Average: all 0.00 0.00 0.04 0.00 0.00 0.04 0.00 0.00 0.00 99.92
Average: 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
Average: 1 0.00 0.00 0.17 0.00 0.00 0.00 0.00 0.00 0.00 99.83
Average: 2 0.00 0.00 0.00 0.00 0.00 0.17 0.00 0.00 0.00 99.83
Average: 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

Compare the results of mpstat with and without parameters:

Stress test localhost

ping -f localhost

Then run the mpstat command in another terminal

mpstat
Linux 3.10.0-1160.71.1.el7.x86_64 (centos) 08/15/2022 _x86_64_ (4 CPU)

09:34:20 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
09:34:20 AM all 0.03 0.00 0.07 0.00 0.00 0.02 0.00 0.00 0.00 99.88

As mentioned above: When mpstat takes no parameters, the output is the average value since the system was started, so there is no change.

mpstat
Linux 3.10.0-1160.71.1.el7.x86_64 (centos) 08/15/2022 _x86_64_ (4 CPU)

09:34:40 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
09:34:40 AM all 0.03 0.00 0.07 0.00 0.00 0.02 0.00 0.00 0.00 99.88

Only by adding the interval can the CPU usage for a certain period of time be displayed.

mpstat 3 10
Linux 3.10.0-1160.71.1.el7.x86_64 (centos)      08/15/2022      _x86_64_        (4 CPU)

09:36:21 AM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
09:36:24 AM  all    1.81    0.00    7.03    0.00    0.00    6.37    0.00    0.00    0.00   84.79
09:36:27 AM  all    1.82    0.00    6.88    0.00    0.00    5.83    0.00    0.00    0.00   85.47
09:36:30 AM  all    1.95    0.00    5.86    0.00    0.00    4.98    0.00    0.00    0.00   87.21
09:36:33 AM  all    3.95    0.00    6.50    0.00    0.00    5.46    0.00    0.00    0.00   84.09
09:36:36 AM  all    4.05    0.00    6.21    0.00    0.00    5.64    0.00    0.00    0.00   84.10
09:36:39 AM  all    4.21    0.00    6.92    0.00    0.00    5.33    0.00    0.00    0.00   83.54
09:36:42 AM  all    3.72    0.00    7.17    0.00    0.00    6.05    0.00    0.00    0.00   83.05
09:36:45 AM  all    3.97    0.00    6.93    0.00    0.00    6.65    0.00    0.00    0.00   82.46
09:36:48 AM  all    4.30    0.00    9.55    0.00    0.00    9.55    0.00    0.00    0.00   76.59
09:36:51 AM  all    4.35    0.00    9.31    0.00    0.00    8.79    0.00    0.00    0.00   77.55
Average:     all    3.44    0.00    7.28    0.00    0.00    6.52    0.00    0.00    0.00   82.76

The above two tables show that when you want to correctly reflect the system situation, you need to use the command parameters correctly. vmstat and iostat also need to pay attention to this issue.