Low Orbit Flux Logo 2 F

Linux Command - mpstat

The Linux mpstat command is used to report CPU related stats. It works great with multi processor systems.

The mpstat command is part of the sysstat package. If mpstat isn’t available on your system you may need to install sysstat first:



sudo apt install sysstat           # Debian/Ubuntu/Mint
sudo yum install sysstat           # RHEL/Fedora 
sudo zypper install sysstat        # OpenSUSE  
sudo pacman -S sysstat             # Arch Linux
sudo emerge -a app-admin/sysstat   # Gentoo

The mpstat command will repeatedly print out reports. You can specify the number of reports and the interval between reports. By default it will only print once and that will be the average values since boot. The first printed report will also probably be the averages since boot ( not confirmed ).

Basic usage format:



mpstat [interval] [count]



mpstat      # single report
mpstat 2    # continous reports every 2 seconds 
mpstat 3 5  # 5 reports, every 3 seconds 

NOTE - the first report printed will be the averages since boot.



mpstat     # show CPU report ( default )
mpstat -u  # show CPU report 
mpstat -n  # show NUMA report 
mpstat -nu # NUMA and CPU report

mpstat  -u -P ALL          # CPU report, all CPUs
mpstat  -n -N ALL          # NUMA report, all nodes
mpstat  -nu -N ALL -P ALL  # NUMA and CPU reports, all CPU and nodes
mpstat  -I ALL             # interrupt statistics


mpstat  -u -P ALL -T       # CPU report, all CPUs, with Topology
mpstat -A                  # -n -u -I ALL -N ALL -P ALL
mpstat -o JSON             # JSON output

Options

-A equivalent to specifying -n -u -I ALL. also implies -N ALL -P ALL unless explicitly set  
-I { keyword[,…] ALL } Report interrupts statistics. Possible keywords are CPU, SCPU, and SUM.
-n Report summary CPU statistics based on NUMA node placement. ‘all’ global average among nodes  
-N { node_list ALL } NUMA nodes to show stats for, ex: 0,2,4-7,12- ALL will report for all global nodes. ‘all’ global average among nodes
-u Report CPU utilization.  
-P { cpu_list ALL } CPUs to show stats for, ex: 0,2,4-7,12- ALL for all CPUs. ‘all’ global average among CPUs
-T Display topology elements in the CPU report ( use with -u )  
-o JSON JSON output  
–dec=x Specify the number of decimal places to use (0 to 2, default value is 2).  
-V Print version number then exit.  

Fields and Keywords

These are the fields.

CPU Report Fields:

CPU Processor number.
%usr Show the percentage of CPU utilization at the user level (application).
%nice Show the percentage of CPU utilization at the user level with nice priority.
%sys Show the percentage of CPU utilization at the system level (kernel). (not interruptes )
%iowait Show the percentage of time CPUs were idle with an outstanding disk I/O request.
%irq Show the percentage of time spent by the CPU or CPUs to service hardware interrupts.
%soft Show the percentage of time spent by the CPU or CPUs to service software interrupts.
%steal Show the percentage of time spent waiting while the hypervisor was servicing another virtual CPU.
%guest Show the percentage of time spent by the CPU or CPUs to run a virtual processor.
%gnice Show the percentage of time spent by the CPU or CPUs to run a niced guest.
%idle Show the percentage of time that the CPU or CPUs were idle ( and not waiting on IO )

CPU report added topology elements:

CORE Logical core number.
SOCK Logical socket number.
NODE Logical NUMA node number.

Field when showing NUMA nodes:

NODE Logical NUMA node number. ‘all’ global average among nodes

Interrupt statistics option keywords ( -I ):

ALL just show all interrupt stats
CPU individual interrupts received per second by the CPUs. See /proc/interrupts for interrupt list.
SCPU individual software interrupt received per second by the CPUs. See /proc/softirqs for sft interrupts.
SUM total number of interrupts per processor.

Output fields:

CPU Processor number. The keyword all indicates that statistics are calculated as averages among all processors.
intr/s Show the total number of interrupts received per second by the CPU or CPUs.