mpstat

On this page 8

mpstat is a command-line utility from the sysstat package that reports processor utilization statistics for each CPU individually or as a system-wide average. In Linux monitoring, it answers a question that aggregate tools often hide: which logical CPUs are busy, and with what kind of work, so that an administrator can separate user code, kernel overhead, interrupt handling, storage waits and hypervisor contention.

Unlike top or htop, which focus on processes, mpstat focuses on processors as the unit of observation. It is lightweight, scriptable and available on almost every distribution, which makes it a standard first step when a multi-core server feels slow while the overall CPU average still looks moderate.

How mpstat collects processor statistics

mpstat reads cumulative tick counters from /proc/stat, the procfs file in which the kernel records how much time each CPU has spent in every execution state since boot. The counters are measured in clock ticks (USER_HZ, usually 100 per second), and mpstat converts them into percentages by sampling the file twice and dividing the difference between two snapshots by the elapsed time.

The basic syntax is mpstat [options] [interval [count]]. Run without an interval, it prints a single report of averages since system boot, which is rarely useful for diagnosing a current problem. With an interval such as mpstat -P ALL 2 5, it prints five reports two seconds apart and finishes with an Average line that summarizes the whole sampling window.

Interrupt statistics come from /proc/interrupts and /proc/softirqs, which mpstat parses when the -I option is given. Because all data comes from these kernel interfaces, mpstat needs no special privileges and adds negligible overhead, even at one-second intervals.

Reading the mpstat CPU columns

Each output row describes one CPU, or all CPUs together, for one interval, and the percentage columns always sum to roughly 100 percent. The following table explains what each column measures and what an unusually high value typically indicates.

ColumnWhat it measuresHigh values usually suggest
%usrTime in user-space code at normal priorityApplication computation, busy loops
%niceUser-space time at a lowered priorityBackground batch jobs or builds
%sysTime in kernel code, excluding interruptsHeavy system calls, locking, memory management
%iowaitIdle time while block I/O was outstandingSlow or saturated storage
%irqTime servicing hardware interruptsNetwork or storage interrupt storms
%softTime servicing softirqsHigh packet rates, network stack processing
%stealTime a virtual CPU waited for the hypervisorOvercommitted host, noisy neighbors
%guest and %gniceTime running a virtual CPU for guestsThis host runs KVM virtual machines
%idleIdle time with no outstanding I/OSpare capacity on that CPU
Main CPU state columns in mpstat output

Two columns are frequently misread. %iowait is a form of idle time, not CPU work: it only shows that the CPU had nothing to run while a disk request was pending, so a busy system can show low iowait even when storage is slow. %steal only appears inside virtual machines and is the clearest evidence that the hypervisor, not the guest, is limiting performance.

Essential mpstat options

Most practical work with mpstat uses a small set of options that select processors, add interrupt data or change the output format. The table below lists the options that experienced administrators use most often.

OptionEffectTypical use
-P ALLReports every logical CPU plus the all rowDetecting per-core imbalance
-P 0,3Reports only the listed CPUsWatching cores pinned to one workload
-uReports CPU utilization only (the default)Explicit scripts and documentation
-I SUMTotal interrupts per second for each CPUQuick interrupt load check
-I CPU or -I SCPUPer-interrupt or per-softirq ratesFinding which device floods one core
-N or --decNUMA node selection, decimal placesLarge multi-socket servers
-AEnables all reports for all CPUsCollecting a complete snapshot
-o JSONMachine-readable JSON outputFeeding scripts or dashboards
Commonly used mpstat options

Option availability depends on the sysstat version: NUMA node reporting and some topology flags appeared only in releases from the 12.x series onward. On older enterprise distributions, man mpstat is the authoritative list for the installed build.

mpstat belongs to a family of sysstat and procps tools, and each answers a different question about system load. Choosing the right one avoids chasing symptoms in the wrong layer, as the comparison below shows.

ToolPrimary unit of observationBest question it answers
mpstatIndividual processorsIs the load evenly spread across cores
pidstatIndividual processes and threadsWhich task consumes the CPU time
vmstatWhole system: CPU, memory, run queueIs the system short of CPU or memory
iostatBlock devices plus a CPU summaryIs a specific disk saturated
sarHistorical system-wide countersWhat happened at 03:00 last night
top and htopInteractive process listWhat is running right now
mpstat and neighboring Linux monitoring tools

A useful workflow is top-down narrowing: vmstat or uptime shows that the system is under pressure, mpstat shows where across the cores the pressure sits, and pidstat or perf identifies the responsible task or function. The sar tool records the same per-CPU data historically through sar -P ALL, which makes mpstat the live counterpart of recorded sar data.

Diagnosing problems with mpstat

The real value of mpstat lies in recognizing patterns across CPUs rather than reading single numbers. The following decision table links common output patterns to their likely cause and the next diagnostic step.

Observed patternLikely causeNext step
One CPU near 100% usr, others idleSingle-threaded bottleneckUse pidstat -t to find the hot thread
One CPU with high %soft or %irqInterrupt affinity concentrated on one coreCheck /proc/interrupts, enable RPS or irqbalance
High %iowait across all CPUsStorage latency or saturationRun iostat -x and inspect await
Sustained %steal above 5-10%Hypervisor contentionAsk the provider or resize the instance
High %sys on many CPUsLock contention or excessive system callsProfile with perf or trace with strace
Typical mpstat patterns and how to follow them up

Thresholds such as steal above 5 to 10 percent are rules of thumb rather than standards; what matters is a sustained deviation from the normal baseline of the same workload. Capturing a baseline with mpstat -P ALL 5 during healthy periods makes later anomalies far easier to judge.

Limitations and common mistakes

mpstat reports time-based utilization, not how much useful work the processor completed, so it inherits several blind spots that practitioners should keep in mind.

  • Logical CPUs are not physical cores: with simultaneous multithreading, two busy hyperthreads share one core, so 50 percent per-thread usage can already mean a saturated core.
  • Frequency scaling is invisible: a CPU at 40 percent busy running at a reduced clock may be closer to its limit than the number suggests.
  • Short intervals are noisy: sub-second spikes average out at five-second intervals, while one-second samples exaggerate random bursts.
  • The first report without an interval is a boot average and should not be mistaken for current load.
  • Container limits are not reflected: cgroup CPU quotas can throttle a container while mpstat on the host still shows idle cores; Pressure stall information is better suited to that case.

In plain words

Modern computers have many processors working side by side, a little like checkout lanes in a supermarket. The usual CPU figure tells you how busy the store is on average, but it cannot tell you that one lane has a long queue while the other seven stand empty.

mpstat shows every lane separately. For each processor it says how much time went to running programs, to the operating system itself, to waiting for the disk or to being idle. That makes it easy to see when one overloaded processor, rather than a lack of overall capacity, is slowing everything down.

A real-world example

An operations engineer manages a Linux web gateway with 16 logical CPUs that starts dropping requests during evening peaks, although the dashboard shows only about 20 percent average CPU usage. She runs mpstat -P ALL -I SUM 2 during the next peak and immediately sees that CPU 0 sits at 0 percent idle, with roughly 60 percent in %soft and 25 percent in %irq, while the other fifteen CPUs are mostly idle.

Inspecting /proc/interrupts confirms that every receive queue of the network card is bound to CPU 0. After enabling irqbalance and spreading the card queues across eight cores, the next mpstat run shows softirq time divided evenly at about 8 percent per core. Dropped requests disappear without any hardware upgrade, and the engineer adds a per-CPU mpstat check to the team runbook.