The mpstat tool reports processor statistics for each available core. Executed without any arguments mpstat will show the global average CPU utilisation since the last boot:
marc:~> mpstat
10:10:05 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
10:10:05 PM all 7.20 0.17 1.96 1.65 0.00 0.01 0.00 1.46 0.00 87.54
-
CPU processor number. The keyword all indicates that statistics are calculated as averages among all processors.
-
%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). Note that this does not include time spent servicing hardware and software interrrupts.
-
%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 by the CPU or CPUs to service hardware interrupts.
-
%soft percentage of time spent by the CPU or CPUs to service software interrupts.
-
%steal percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
-
%guest percentage of time spent by the CPU or CPUs to run a virtual processor.
-
%gnice percentage of time spent by the CPU or CPUs to run a niced guest.
-
%idle percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
We can specify intervals and iterations:
marc:~> mpstat 5 3
.
10:18:53 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
10:18:58 PM all 0.20 0.40 0.20 0.03 0.00 0.00 0.00 0.00 0.00 99.17
10:19:03 PM all 0.35 0.00 0.08 0.13 0.00 0.00 0.00 0.00 0.00 99.45
10:19:08 PM all 0.25 0.00 0.15 0.03 0.00 0.00 0.00 0.00 0.00 99.57
Average: all 0.27 0.13 0.14 0.06 0.00 0.00 0.00 0.00 0.00 99.40
We can extract fine-grained statistics on a per core basis for all cores…
marc:~> mpstat -P ALL 5 2
.
10:20:15 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
10:20:20 PM all 0.23 0.00 0.08 0.05 0.00 0.00 0.00 0.00 0.00 99.65
10:20:20 PM 0 0.40 0.00 0.20 0.20 0.00 0.00 0.00 0.00 0.00 99.20
10:20:20 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
10:20:20 PM 2 0.20 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 99.60
10:20:20 PM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
10:20:20 PM 4 0.40 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.40
10:20:20 PM 5 0.80 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.20
10:20:20 PM 6 0.20 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.60
10:20:20 PM 7 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
.
10:20:20 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
10:20:25 PM all 0.25 0.00 0.10 0.03 0.00 0.00 0.00 0.00 0.00 99.62
10:20:25 PM 0 0.20 0.00 0.20 0.20 0.00 0.00 0.00 0.00 0.00 99.40
10:20:25 PM 1 0.40 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.60
10:20:25 PM 2 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.80
10:20:25 PM 3 0.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 99.80
10:20:25 PM 4 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
10:20:25 PM 5 1.00 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 98.80
10:20:25 PM 6 0.20 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.80
10:20:25 PM 7 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
.
Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
Average: all 0.24 0.00 0.09 0.04 0.00 0.00 0.00 0.00 0.00 99.64
Average: 0 0.30 0.00 0.20 0.20 0.00 0.00 0.00 0.00 0.00 99.30
Average: 1 0.20 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.80
Average: 2 0.10 0.00 0.10 0.10 0.00 0.00 0.00 0.00 0.00 99.70
Average: 3 0.00 0.00 0.10 0.00 0.00 0.00 0.00 0.00 0.00 99.90
Average: 4 0.20 0.00 0.10 0.00 0.00 0.00 0.00 0.00 0.00 99.70
Average: 5 0.90 0.00 0.10 0.00 0.00 0.00 0.00 0.00 0.00 99.00
Average: 6 0.20 0.00 0.10 0.00 0.00 0.00 0.00 0.00 0.00 99.70
Average: 7 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
… or for specific ones…
root:/tmp> mpstat -P 0,1 2 2
12:52:26 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
12:52:28 PM 0 0.50 0.00 0.50 0.00 0.00 0.00 0.00 0.00 0.00 99.00
12:52:28 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
12:52:30 PM 0 0.50 0.00 0.00 2.01 0.00 0.00 0.00 0.00 0.00 97.49
12:52:30 PM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
Average: 0 0.50 0.00 0.25 1.00 0.00 0.00 0.00 0.00 0.00 98.25
Average: 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
With the -I flag we get interrupt statistics. We can combine it with SUM to get overall interrupt figures…
root:/tmp> mpstat -I SUM 5 2
01:04:30 PM CPU intr/s
01:04:35 PM all 480.20
01:04:40 PM all 151.60
Average: all 315.90
… or with CPU to get figures for only one core (core ID 0 in the example below) …
root:/tmp> mpstat -P 0 -I CPU 5 2
01:08:37 PM CPU 0/s 1/s 8/s 9/s 12/s 16/s 17/s 23/s 25/s 26/s 27/s 28/s 29/s 30/s 31/s 32/s 33/s 34/s NMI/s LOC/s SPU/s PMI/s IWI/s RTR/s RES/s CAL/s TLB/s TRM/s THR/s MCE/s MCP/s HYP/s ERR/s MIS/s
01:08:42 PM 0 0.00 0.20 0.00 0.00 0.00 0.00 0.00 0.00 7.80 0.00 0.00 0.00 10.40 0.00 0.00 37.40 0.00 0.00 0.00 27.60 0.00 0.00 0.00 0.00 0.60 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:08:47 PM 0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 2.00 0.00 0.00 0.00 10.60 0.00 0.00 41.00 0.00 0.00 0.00 35.80 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: 0 0.00 0.10 0.00 0.00 0.00 0.00 0.00 0.00 4.90 0.00 0.00 0.00 10.50 0.00 0.00 39.20 0.00 0.00 0.00 31.70 0.00 0.00 0.00 0.00 0.80 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
… and with SCPU to get statistics on software interrupts…
root:/tmp> mpstat -P 0 -I SCPU 5 2
01:13:23 PM CPU HI/s TIMER/s NET_TX/s NET_RX/s BLOCK/s BLOCK_IOPOLL/s TASKLET/s SCHED/s HRTIMER/s RCU/s
01:13:28 PM 0 0.00 39.80 0.00 0.00 14.20 0.00 0.20 34.60 0.20 39.80
01:13:33 PM 0 0.00 35.00 0.00 0.00 16.40 0.00 0.00 26.40 0.40 35.00
Average: 0 0.00 37.40 0.00 0.00 15.30 0.00 0.10 30.50 0.30 37.40
We can have a look at /proc/interrupts and /proc/softirqs to get the description of the hardware and software interrupts in the system.