mpstat
Report per-processor CPU usage statistics
By CMD Script Team · 4 min read · Last updated
mpstat [OPTIONS] [INTERVAL] [COUNT]Options
| Flag | Description |
|---|---|
-P | Select which CPU(s) to report on, e.g. -P ALL or -P 0,1 |
-A | Equivalent to -I ALL -u -P ALL: report all available statistics for all CPUs |
-u | Report CPU utilization (the default report type) |
-I | Report interrupt statistics, e.g. -I SUM |
-o | Output in JSON format instead of plain text (newer sysstat versions) |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS (not available; part of sysstat, Linux-only)
What it does
mpstat (multi-processor statistics) reports CPU utilization broken down into categories
like %usr (user space), %sys (kernel), %iowait (waiting on disk I/O), %irq, and
%idle, either as an aggregate across all cores or per individual core. It's part of the
sysstat package alongside iostat and sar, and is the standard tool for understanding
where CPU time is going and whether load is balanced across cores — something plain
top summarizes less precisely.
Beginner examples
mpstat— print one CPU utilization report averaged since bootmpstat 1— print a new report every 1 second, continuouslympstat 1 5— print 5 reports at 1-second intervals, then stopmpstat -P ALL 1— show a separate line per CPU core, refreshed every second
mpstat 1 5
Advanced examples
- Watch for I/O bottlenecks by focusing on
%iowait:mpstat 2 | awk '{print $1, $6}' - Check whether load is balanced across cores or piling onto one:
mpstat -P ALL 1 5 - Combine with interrupt statistics to correlate CPU spikes with hardware interrupts:
mpstat -I SUM 1 - Get everything at once (utilization + interrupts, all CPUs):
mpstat -A - Log CPU stats to a file for later review during a load test:
mpstat -P ALL 5 > cpu_report.log &
mpstat -P ALL 1 5
Common mistakes
- Running
mpstatwith no arguments and thinking the single report is "live" data — with no interval, it reports the average since boot, not the current moment. - Ignoring
%iowaitand assuming a "high CPU" problem when the real bottleneck is disk or network I/O the CPU is waiting on. - Not installing
sysstatfirst — many minimal Linux images and containers don't include it by default, sompstat: command not foundis common on fresh systems. - Looking only at the aggregate
allline and missing that one specific core is saturated while others sit idle (a sign of poor thread/process affinity or a single-threaded bottleneck).
Tips
- Use
mpstat -P ALLwhenever you suspect a workload isn't parallelizing well; a single hot core next to several idle ones is a strong single-thread bottleneck signal. - Pair
mpstat 1in one terminal withiostat 1in another during a performance investigation — CPU and disk stats together usually explain a slowdown. - The last column,
%idle, is the complement of everything else; if user+sys+iowait looks fine but%idleis still low, check%irqand%softfor interrupt-heavy workloads (e.g. high network traffic). - Run
mpstat 1 5(a handful of samples) rather than a single report when explaining a transient spike — one report can be misleading if it lands on a quiet moment.
Best practices
- Always specify an interval (
mpstat 1) rather than relying on the boot-average single report when diagnosing current system behavior. - In monitoring/logging scripts, pin a fixed count (
mpstat 1 60) so the job terminates predictably rather than running forever. - Correlate
mpstat's%iowaitspikes withiostat's device-level throughput to confirm whether a specific disk is the source of the wait. - Install
sysstatas part of your base server image if you regularly need CPU/IO diagnostics, rather than installing it reactively during an incident.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Diagnosing whether a slow batch job is CPU-bound, I/O-bound, or waiting on interrupts
by watching
%usr,%iowait, and%irqduring a run. - Confirming that a multi-threaded application is actually using multiple cores by
checking
mpstat -P ALLfor balanced utilization across cores. - Capacity planning: logging
mpstatoutput over a peak traffic window to decide whether a server needs more CPU cores or the workload needs better parallelization.
Common interview questions
- What does %iowait mean and why does it matter? It's the percentage of time a CPU was otherwise idle but had a pending disk I/O request; high %iowait means disk latency, not CPU compute, is the bottleneck, even though the CPU "looks busy" in some tools.
- How would you check if load is evenly spread across CPU cores?
mpstat -P ALL 1prints a per-core row each interval, letting you compare%usr/%idleacross cores to spot an imbalance. - What package provides mpstat and what other tools come with it? The
sysstatpackage, which also providesiostat,sar,pidstat, andsadc/sadffor historical performance data collection.
Frequently Asked Questions
How do I install mpstat?
mpstat ships in the sysstat package. Install it with sudo apt install sysstat on Debian/Ubuntu or sudo dnf install sysstat on Fedora, then run mpstat directly.
What does mpstat 1 do?
It prints a CPU utilization report every 1 second, continuously, until you stop it with Ctrl+C. Add a count, like mpstat 1 5, to print exactly 5 reports and then stop.
How is mpstat different from top?
top shows per-process resource usage in an interactive full-screen view; mpstat focuses purely on per-CPU-core utilization breakdown (user, system, iowait, idle, etc.) in a simple scrollable text format, which is easier to log and parse.
What does %iowait mean in mpstat's output?
It's the percentage of time a CPU was idle while the system had an outstanding disk I/O request in flight — a high %iowait suggests disk I/O, not CPU, is the bottleneck.
Cheat sheet
Download a quick-reference cheat sheet for mpstat.