Calculate CPU utilization percentage from user, system and idle time measurements.
The Linux kernel exposes cumulative CPU time counters in /proc/stat, measured in jiffies since boot. Taking two snapshots and computing the delta of each field (or using cumulative totals as a rough single-point estimate, as here) lets you derive utilization: the busy time is user + nice + system + irq + softirq + steal, and total time additionally includes idle and iowait. Dividing busy by total gives the percentage of CPU time spent doing work.
CPU usage percentage
usage% = 100 × (user+nice+system+irq+softirq+steal) / (user+nice+system+idle+iowait+irq+softirq+steal)
For an accurate instantaneous reading, take two /proc/stat snapshots a second or two apart and feed the *differences* of each field into this calculator — that is what `top` and `mpstat` do internally. Using raw cumulative totals from boot gives an average over the machine's entire uptime.
Steal time is CPU time a virtual machine's guest OS was ready to run but the hypervisor gave the physical CPU to another guest instead — a useful signal of noisy-neighbor contention on shared virtualized or cloud hosts.
iowait represents idle time where the CPU had no runnable task but was waiting on a pending disk I/O — the CPU wasn't actually executing instructions, so it counts toward idle capacity, not utilization.