Linux Performance Monitoring – mpstat

Linux server performance monitoring through the ‘mpstat’ command, is one of the oldest and most valuable ways to capture CPU statistics. If the system is a multi-core processor, then the mpstat command helps monitor each core CPU. If a Linux kernel has dual processors with dual cores, the command will report 4 CPUs statistics. The mpstat command provides the same CPU utilization statistics as vmstat, but mpstat breaks the statistics out on a per-processor basis.

‘mpstat’ stands for ‘Multiple Processor Statistics’, although different sources have another suggestion for ‘m’. ‘mpstat’ is a utility like ‘vmstat’ and it provides processors-related statistics.

Command Syntex:

$ mpstat

Output

Figure 01

Refer to Figure 01, the mpstat command output has two sections which are:

  1. System Configuration: This is the first section displayed at the top. It provides the basic information about the system like version, server name, no. of CPUs etc.
  2. Utilization Statistics: The second section displays the different metrics of CPU Utilization. If you use delay value then the statistics are displayed in intervals and at any time the values of these metrics are deltas from the previous intervals.

Field Description

  • Timestamp: The time at which stats are captured.
  • CPU: It shows the Processor Number. The keyword all indicates that statistics are calculated as averages among all processors. The first processor with CPU 0, the second one with CPU 1 and so on.
  • %usr: It shows the percentage of CPU utilization that occurred while executing at the user level (application).
  • %nice: It shows the percentage of CPU utilization that occurred while executing at the user level with nice priority.
  • %sys: It shows the percentage of CPU utilization that occurred while executing at the system level (kernel). Note that this does not include time spent servicing hardware and software interrupts.
  • %iowait: It shows the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
  • %irq: It shows the percentage of time spent by the CPU or CPUs to service hardware interrupts.
  • %soft: It shows the percentage of time spent by the CPU or CPUs to service software interrupts.
  • %steal: It shows the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
  • %guest: It shows the percentage of time spent by the CPU or CPUs to run a virtual processor.
  • %gnice: It shows the percentage of time spent by the CPU or CPUs to run a niced guest.
  • %idle: It shows the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.

Options

-A: It provides all the process-related statistics in one go. ‘all’ value under the ‘CPU’ column provides an average of all the CPUs stats. ‘-A’ option is equivalent to:
$ mpstat -n -u -I ALL -N ALL -P ALL

Figure 02
Figure 03

-I: This option provides the statistics about interrupts and its keywords are CPU, SCPU, SUM and ALL.

Figure 04

-n It displays node-wise stats. The possible keywords are <node-list> and ALL. The keyword ‘ALL’ indicates that statistics are calculated as averages among all nodes.

Figure 05

-o JSON: This option displays the statistics in JSON format.

Figure 06

[Delay Value]: The delay between the command output updates in seconds. If no delay is specified, only one output is printed with the average values of all the CPUs. In the below example, 5 seconds is a delay between command outputs.

Figure 07

[Count Value]: It represents the number of required outputs. In the absence of a count value, when the delay is defined, the default is infinite outputs until the command gets killed. In the below example, the count value is 4 and hence only 4 outputs are displayed at the interval of 10 seconds along with the Average.

Figure 08

These are the important options and keywords related to the mpstat command.

How to capture mpstat during a load test?

Before starting the load test you have to run the below command:

$ nohup mpstat [Delay Value] [Count Value] > [File Name] &

Example: If you want to run a load test for 1 hour and need to capture the server statistics in the mpstatLoadTest.dat file in every 10 seconds then the calculation of the Count Value will be:
=> 1 hour = 3600 seconds
=> 3600/10 = 360 // Count Value

And, the command will be:

$ nohup mpstat 10 360 > mpstatLoadTest.dat &

Refer mpstatLoadTest.dat file, after the completion of the test and analyse the result.

How to analyse mpstat file?

You can simply use MS Excel to analyse the mpstat file. Use the ‘Text to Column’ option so that stats are separated into columns and then you can plot the graphs by selecting the required columns.

  1. ‘%usr’ value should be less than 70% (In ideal conditions)
  2. In case the ‘%iowait’ value increases that means the CPU has to wait for the IO resource.

How to capture mpstat for all nodes during a load test?

Before starting the load test you have to run the below command:

$ nohup mpstat -P ALL [Delay Value] [Count Value] > [File Name] &

Example: If you want to run a load test for 1 hour and need to capture the server statistics in the mpstatLoadTest.dat file in every 10 seconds then the calculation of the Count Value will be:
=> 1 hour = 3600 seconds
=> 3600/10 = 360 // Count Value

And, the command will be:

$ nohup mpstat -P ALL 10 360 > mpstatLoadTest.dat &

Important Points

  1. The mpstat command with no options generates a single report that contains the performance statistics for all logical processors since boot time.
  2. mpstat helps to understand the CPU utilization and pattern of the Linux system during the performance testing.
  3. Calculate the Count Value by providing some extra time for the load test, so that you can have Linux server monitoring stats for pre, post and during the test.

You may be interested:


Leave a Comment