Linux mpstat Command 鈥?Report Processor Statistics

         Modern computers typically use multi-processors or quad-core single processors. On the server side, more processors or cores mean greater capability, but on the flip side, applications also demand higher power consumption. You may have also encountered a scenario where your CPU utilization is very high, yet you feel like you aren’t running any programs at all. In these situations on a Linux system, you can use mpstat to monitor such activity. 

What is mpstat

mpstat is used to monitor CPU utilization on your system. If your system has multiple processors, it becomes even more useful. The first processor is labeled as CPU 0, the second as CPU 1, and so on. In the manual, mpstat is described as follows:

The mpstat command writes the status of each available processor to standard output, with the first processor defaulting to processor 0. A global average status across all processors is also reported. The mpstat command can be used on both SMP and UP machines, but on UP machines, only the global average status will be printed. If no specific action is selected, it defaults to reporting CPU utilization.

How to Run mpstat

Simply type mpstat in your terminal to run it.

$ mpstatLinux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)03:29:29 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle03:29:29 PM all 6.30 0.06 1.94 3.75 0.00 0.06 0.00 0.00 87.88

If you encounter an error such as command not found or similar, it means you might not have mpstat installed.

If you are using CentOS, RedHat or Fedora, run the following command to install mpstat:

# yum install sysstat

If you are using Debian, Ubuntu or its derivatives, run the following command to install mpstat:

# apt-get install sysstat

Here is how to understand the information displayed above.

  • 03:29:29 PM : The time mpstat was run
  • all : Refers to all CPUs
  • %usr : Shows the percentage of CPU utilization while executing at the user level (e.g., applications)
  • %nice : Shows the percentage of CPU utilization while executing at the user level with nice priority
  • %sys : Shows the percentage of CPU utilization while executing at the system level (e.g., kernel)
  • %iowait : Shows the percentage of time CPUs were idle during which the system had an outstanding disk I/O request
  • %irq : Shows the percentage of time spent by CPUs servicing hardware interrupts
  • %soft : Shows the percentage of time spent by CPUs servicing software interrupts
  • %steal : Shows the percentage of time spent in involuntary wait by the virtual CPU while the hypervisor was servicing another virtual processor
  • %guest : Shows the percentage of time spent by the CPU to run a virtual processor
  • %idle : Shows the percentage of time CPUs were idle and the system did not have an outstanding disk I/O request

Printing Per-Processor CPU Utilization

As shown in the command result above, our system has two CPUs. If you prefer, you can use the -P parameter followed by the CPU number to get the utilization of a specific CPU.

$ mpstat -P 0Linux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)03:54:00 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle03:54:00 PM 0 3.82 0.01 1.16 3.88 0.00 0.06 0.00 0.00 91.06$ mpstat -P 1Linux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)03:53:58 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle03:53:58 PM 1 16.52 0.20 4.48 0.46 0.00 0.04 0.00 0.00 78.30

Printing Utilization for All CPUs

You can also print the CPU utilization for each processor on one page by using the -P ALL parameter.

$ mpstat -P ALLLinux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)04:07:36 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle04:07:36 PM all 6.02 0.04 1.72 2.99 0.00 0.05 0.00 0.00 89.1704:07:36 PM 0 3.84 0.01 1.15 3.72 0.00 0.06 0.00 0.00 91.2104:07:36 PM 1 13.55 0.15 3.66 0.46 0.00 0.03 0.00 0.00 82.15

Printing CPU Utilization with an Interval

If you want to observe changes in CPU utilization, you can use a time interval. Here is an example.

$ mpstat 3 4Linux 3.2.0-57-generic (USERNB01) 12/12/2013 _x86_64_ (2 CPU)04:27:11 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle04:27:14 PM all 0.67 0.00 0.34 0.00 0.00 0.00 0.00 0.00 98.9904:27:17 PM all 1.17 0.00 0.33 1.33 0.00 0.00 0.00 0.00 97.1704:27:20 PM all 0.84 0.00 0.17 0.00 0.00 0.00 0.00 0.00 98.9904:27:23 PM all 1.00 0.00 0.17 1.51 0.00 0.00 0.00 0.00 97.32Average: all 0.92 0.00 0.25 0.71 0

Leave a Comment

Your email address will not be published.