mpstat
Report processor related statistics
TLDR
Display CPU statistics every 2 seconds
Display 5 reports, one by one, at 2 second intervals
Display 5 reports, one by one, from a given processor, at 2 second intervals
SYNOPSIS
mpstat [ -A ] [ -I { SUM | CPU | ALL } ] [ -P { cpu_list | ALL } ] [ -u ] [ -V ] [ interval [ count ] ]
PARAMETERS
interval
Specifies the delay in seconds between each report. A value of zero (0) indicates a single report with statistics since boot.
count
Specifies the number of reports generated. If interval is specified without count, reports are generated continuously.
-A
Displays all activities. This option is equivalent to specifying -u -I ALL -P ALL.
-I { SUM | CPU | ALL }
Reports global (SUM), per-CPU (CPU), or all (ALL) interrupt statistics. -I SUM is the default.
-P { cpu_list | ALL }
Displays statistics for the specified processor(s) or all processors (ALL). cpu_list is a comma-separated list of CPU numbers (e.g., 0,2,4).
-u
Reports CPU utilization statistics (the default if no other flags are given and no interval/count are specified).
-V
Displays the version number of the mpstat command.
DESCRIPTION
The mpstat command is a powerful utility within the sysstat package designed to monitor and report processor-related statistics for both individual CPUs and the system as a whole in Linux. It provides detailed insights into how your system's CPUs are being utilized, including user-level processes, system-level processes, I/O wait times, idle times, and interrupt handling. This makes it invaluable for performance analysis, identifying CPU bottlenecks, and understanding system load distribution across multiple cores. By specifying an interval and count, mpstat can provide real-time updates, allowing administrators and developers to observe trends and troubleshoot performance issues effectively. It differentiates itself by offering per-CPU breakdown, which is essential for diagnosing issues in multi-core environments where one core might be overloaded while others are idle.
CAVEATS
- The mpstat command is part of the sysstat package, which must be installed on your Linux system (e.g., sudo apt-get install sysstat on Debian/Ubuntu, sudo yum install sysstat on RHEL/CentOS).
- Data accuracy relies on the kernel's /proc/stat file.
- Interpreting the output requires understanding of CPU states like %usr, %sys, %iowait, and %idle.
- Running mpstat with a very small interval can add slight overhead, though usually negligible.
OUTPUT INTERPRETATION
Understanding the columns displayed by mpstat is key to effective analysis.
%usr: Percentage of CPU utilization that occurred while executing at the user level (application).
%nice: Percentage of CPU utilization that occurred while executing at the user level with nice priority.
%sys: Percentage of CPU utilization that occurred while executing at the system level (kernel).
%iowait: Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%irq: Percentage of time spent servicing hardware interrupts.
%softirq: Percentage of time spent servicing software interrupts.
%steal: Percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor. (Relevant in virtualized environments).
%guest: Percentage of time spent by the virtual CPU or CPUs for running a guest (virtual machine) operating system.
%gnice: Percentage of time spent by the virtual CPU or CPUs for running a niced guest (virtual machine) operating system.
%idle: Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
Note: The sum of these percentages should be approximately 100%.
HISTORY
mpstat is a component of the comprehensive sysstat utilities suite, which has been under continuous development for Linux systems since the late 1990s. Developed primarily by Sébastien Godard, sysstat tools like mpstat emerged as essential tools for system administrators to monitor and diagnose performance issues, particularly as multiprocessor systems became more prevalent. Its development has focused on providing granular, real-time, and historical data for various system resources, making it a cornerstone of Linux performance analysis.