mpstat: CPU statistics at a glance


mpstat: CPU statistics at a glance

Pragmatic quick tour for beginners and intermediate users.

What mpstat does

  • mpstat prints per CPU and aggregate statistics about CPU usage since boot and over intervals.
  • It relies on the sysstat package and reads data from /proc/stat.

Quick start (examples first)

1) Display CPU statistics every 2 seconds

mpstat 2
  • This will print a fresh report every 2 seconds until you stop it with Ctrl+C.

2) Display 5 reports, one by one, at 2 second intervals

mpstat 2 5
  • You get a sequence of 5 reports, each 2 seconds apart.

3) Display 5 reports, one by one, from a given processor at 2 second intervals

mpstat -P 0 2 5
  • Replace 0 with the CPU number you care about. Other CPUs are not shown in the per CPU line.

How to read the output (quick guide)

  • The first line is an overall summary since boot
  • The following lines show per CPU usage metrics such as user, system, idle, iowait, etc.
  • Look at the idle percentage to gauge how saturated your CPU is

Common pitfalls

  • mpstat might not be installed by default; install the sysstat package on Debian/Ubuntu with sudo apt install sysstat or the equivalent on your distro
  • The statistics are affected by system activity; for stable baselines, run a few steady-state reports before drawing conclusions
  • If you specify a processor with -P, ensure the index exists on your system; otherwise you may get no per CPU line

Tips and tricks

  • Use mpstat in scripts to log CPU usage over time; redirect output to a file for later analysis
  • Combine with grep or awk to extract specific fields, e.g. mpstat 2 5 | tail -n +3 to skip the header lines
  • For a quick health check, run with a short interval and watch the idle percentage

More resources

  • Official page and man page: mpstat on manned.org
  • If you see outdated cache info in your environment, consider updating tldr pages with tldr —update

See Also