Mpstat stands for Multiprocessor Statistics, a real-time monitoring tool that reports CPU Statistics in the /proc/stat file. In addition, you can view specific CPU information. The most important features of MPstat are: You can view statistics for each computing core in a multi-core CPU. A similar tool, vmstat, can only view the overall CPU status of the system.

Command format:

Usage: mpstat [ options ] [ <interval> [ <count> ] ]
Options are:
[ -A ] [ -u ] [ -V ] [ -I { SUM | CPU | SCPU | ALL } ]
[ -P { <cpu> [,...] | ON | ALL } ]
Copy the code

OPTIONS:

  • -A: equal to -u -i ALL -p ALL

  • -I: You can specify SUM CPU SCPU ALL. SUM indicates the total number of interrupts per processor. CPU indicates the number of interrupts per second for each core.

  • -p: indicates the CPU number. Generally, ALL is used

  • -u: displays the column information

  • -v: Views the tool version

View the current running status of all cpus and update it every two seconds for five times

[root@localhost ~]# mpstat 2 5Linux 3.10.0-1062.el7.x86_64 (localhost.localdomain) 03/11/2020_x86_64_ (4 CPU) 03:59:44AM CPU %usr %nice %sys %iowait % IRq % Soft % Steal %guest % gnICE % Idle 03:59:46 AM All 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 03:59:48am All 0.00 0.00 0.00 0.00 0.00 0.00 0.00 03:59:50 AM All 0.00 0.00 0.13 0.00 0.00 0.00 0.00 0.00 0.00 99.87 03:59:52 AM All 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 03:59:54 AM All 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Average: All 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00Copy the code

Output all CPU usage every one second

[root@localhost ~]# mpstat -P ALL 1 1Linux 3.10.0-1062.el7.x86_64 (localhost.localdomain) 03/11/2020_x86_64_ (4 CPU) 03:51:28 AM CPU %usr %nice %sys %iowait % IRq % Soft % Steal %guest % gnICE % Idle 03:51:29 AM All 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 03:51:29 AM 0 0.00 0.00 0.00 0.00 0.00 0.00 03:51:29 AM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 03:51:29 AM 2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 03:51:29 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: 0.00 0.00 0.00 0.00 0.00 0.00 Average: 0.00 0.00 0.00 0.00 0.00 0.00 Average: 0.00 0.00 0.00 0.00 0.00 0.00 Average: 0.00 0.00 0.00 0.00 0.00 0.00 Average: 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00Copy the code

Field analysis:

  • CPU: indicates the process ID of each CPU

  • %usr: indicates the CPU usage in user mode

  • %nice: indicates the CPU usage of the user with the NICE priority

  • %sys: displays the percentage of CPU usage that occurs during kernel execution. This does not include time spent maintaining hardware and software outages.

  • % ioWAIT: displays the percentage of time that the CPU or CPU is idle when the system has pending disk I/O requests

  • % IRQ: The percentage of time spent by the system serving hard interrupts

  • %soft: percentage of the time spent by the system to service the soft interrupt cost

  • % STEAL: Displays the percentage of time the virtual CPU or CPU is forced to wait while the hypervisor serves another virtual processor

  • %guest: The amount of time spent by the CPU processing virtual processes

  • % IDEL: indicates the idle CPU percentage

View statistics about all CPU soft interrupts

[root@localhost ~]# mpstat -I SCPU 1Linux 3.10.0-1062.el7.x86_64 (localhost.localdomain) 03/11/2020_x86_64_ (4 CPU) 04:18:21 AM CPU HI/ S TIMER/s NET_TX/s NET_RX/s BLOCK/s BLOCK_IOPOLL/s TASKLET/s SCHED/s HRTIMER/s RCU/s 04:18:22AM 0 0.00 30.69 0.99 0.00 0.99 0.00 0.00 24.75 0.00 7.92 04:18:22 AM 1 0.00 7.92 0.00 0.00 0.00 0.00 4.95 0.00 2.97 04:18:22 AM 2 0.00 5.94 0.00 0.99 0.00 0.00 0.00 5.94 0.00 0.99 04:18:22 AM 3 0.00 5.94 0.00 0.00 0.00 0.00 1.98 0.00 3.96 04:18:23 AM 0 0.00 29.00 0.00 0.00 0.00 0.00 23.00 0.00 7.00 04:18:23 AM 1 0.00 4.00 0.00 0.00 0.00 0.00 3.00 04:18:23 AM 2 0.00 5.00 0.00 3.00 0.00 0.00 0.00 1.00 04:18:23 AM 3 0.00 6.00 0.00 0.00 0.00 0.00 4.00 04:18:24 AM 0 0.00 19.00 0.00 0.00 1.00 0.00 16.00 0.00 3.00 04:18:24 AM 1 0.00 9.00 0.00 0.00 0.00 8.00 0.00 1.00 04:18:24 AM 2 0.00 6.00 0.00 2.00 0.00 0.00 0.00 2.00 04:18:24 AM 3 0.00 1.00 0.00 0.00 0.00 0.00 1.00 0.00 1.00Copy the code