Load, vmstat & iostat
"The server is slow" needs a first minute of triage that tells you which resource is the problem: CPU, memory, disk or network, or none of them (the app is waiting on something else). This lesson covers the classic tools for that minute. ps, kill & top showed processes; here the view is the whole machine. Their numbers describe a live system, so the transcripts are sample sessions from a 4-vCPU server under load, and the arithmetic behind them runs as models.
The first 60 seconds
| Command | Look for |
|---|---|
uptime |
load averages, and their trend (1 vs 15 minutes) |
dmesg -T | tail / journalctl -k -n 20 |
OOM kills, disk errors, network link flaps |
vmstat 1 5 |
run queue, swapping, CPU split (user/system/iowait/steal) |
mpstat -P ALL 1 3 |
one CPU at 100% (a single-threaded bottleneck) |
pidstat 1 3 |
which processes use the CPU |
iostat -xz 1 3 |
per-disk utilisation, latency, queue |
free -m |
available memory, swap in use |
sar -n DEV 1 3, ss -s |
network throughput, socket counts |
top / htop |
everything at once, to confirm |
mpstat, pidstat, iostat and sar come with the sysstat package, which can also record history (sar -u -f /var/log/sysstat/sa15 shows yesterday's CPU), the only way to answer "what happened at 03:00?" without a monitoring system.
Load average
$ uptime
10:42:07 up 12 days, 3:18, 2 users, load average: 7.92, 5.10, 2.31
$ nproc
4The load average counts tasks that are running or waiting for a CPU, plus tasks in uninterruptible sleep (state D, usually waiting for disk I/O or NFS). The three numbers are exponentially damped averages over 1, 5 and 15 minutes. Compare them with the number of CPUs: 7.92 on 4 CPUs means about 4 tasks were waiting on average over the last minute, and the rising sequence (2.31 → 5.10 → 7.92) says it is getting worse. But Linux's load includes I/O waits, so a high load with idle CPUs points at storage, not CPU.
The averages are a moving average updated every 5 seconds: load = load × e^(-5/60) + n × (1 − e^(-5/60)) for the 1-minute value, with 300 and 900 seconds for the others. A model shows why the 1-minute value reacts quickly and the 15-minute value lags:
import math
def simulate(runnable, minutes):
loads = [0.0, 0.0, 0.0]
decay = [math.exp(-5 / w) for w in (60, 300, 900)]
for tick in range(minutes * 12): # one tick every 5 s
n = runnable(tick * 5)
loads = [l * d + n * (1 - d) for l, d in zip(loads, decay)]
if (tick + 1) % 12 == 0:
print(f"min {(tick + 1) // 12:>2}: tasks={n} load average: {loads[0]:.2f}, {loads[1]:.2f}, {loads[2]:.2f}")
# a 4-CPU box: idle, then a batch job keeps 8 tasks runnable for 10 minutes, then idle again
simulate(lambda s: 8 if 60 <= s < 660 else 0, 16)min 1: tasks=0 load average: 0.00, 0.00, 0.00
min 2: tasks=8 load average: 5.06, 1.45, 0.52
min 3: tasks=8 load average: 6.92, 2.64, 1.00
min 4: tasks=8 load average: 7.60, 3.61, 1.45
min 5: tasks=8 load average: 7.85, 4.41, 1.87
min 6: tasks=8 load average: 7.95, 5.06, 2.27
min 7: tasks=8 load average: 7.98, 5.59, 2.64
min 8: tasks=8 load average: 7.99, 6.03, 2.98
min 9: tasks=8 load average: 8.00, 6.38, 3.31
min 10: tasks=8 load average: 8.00, 6.68, 3.61
min 11: tasks=8 load average: 8.00, 6.92, 3.89
min 12: tasks=0 load average: 2.94, 5.66, 3.64
min 13: tasks=0 load average: 1.08, 4.64, 3.41
min 14: tasks=0 load average: 0.40, 3.80, 3.19
min 15: tasks=0 load average: 0.15, 3.11, 2.98
min 16: tasks=0 load average: 0.05, 2.54, 2.79
After the job ended at minute 11, the 1-minute value dropped below 1 within a few minutes while the 15-minute value stayed high for a long time. So a high 15-minute and low 1-minute load means "it was bad, it is recovering"; the reverse means "it just started".
vmstat: one line per second
$ vmstat 1 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
9 0 0 312480 80212 2410388 0 0 4 36 4102 7310 92 6 2 0 0
8 0 0 311904 80212 2410412 0 0 0 48 4087 7275 93 6 1 0 0
2 6 0 309112 80220 2413020 0 0 41280 120 3011 5120 21 5 30 44 0
1 7 0 307640 80220 2415968 0 0 52224 64 2890 4987 15 4 33 48 0
1 6 0 306880 80228 2418112 0 0 49920 72 2955 5004 14 4 35 47 0| Column | Meaning | Worry when |
|---|---|---|
r |
runnable tasks (running + waiting for CPU) | consistently above the CPU count: CPU saturated |
b |
tasks blocked in uninterruptible sleep (I/O) | consistently above 0 |
si / so |
memory swapped in / out per second | any steady so: memory pressure |
bi / bo |
blocks read / written per second | compare with what the disk can do |
us sy |
CPU time in user / kernel code | sy high: syscalls, context switches, network |
wa |
CPU idle while I/O is outstanding | high with high b: storage bound |
st |
time stolen by the hypervisor | above a few %: noisy neighbour or burst credits exhausted (cloud) |
The first two lines show a CPU-bound workload (r 8–9 on 4 CPUs, us 92%). The last three show something else: few runnable tasks, 6–7 blocked, 44–48% iowait, 40–50 MB/s being read: the box is waiting for its disk. The first line of vmstat is the average since boot; ignore it.
iostat: which disk, and how slow?
$ iostat -xz 1 2 | sed -n '/Device/,$p' | tail -4
Device r/s rkB/s r_await rareq-sz w/s wkB/s w_await aqu-sz %util
nvme0n1 12.00 384.00 0.41 32.00 18.00 296.00 0.62 0.02 1.20
nvme1n1 821.00 52544.00 21.37 64.00 4.00 64.00 12.75 17.60 99.60nvme1n1 (the database volume) is the problem: %util near 100, a queue (aqu-sz) of 17 and 21 ms average read latency, where this volume normally answers in under 1 ms. %util alone can mislead on SSDs and RAID (they serve many requests in parallel, so 100% "busy" isn't necessarily saturated); latency (r_await, w_await) and queue size are the better signals. Next steps: pidstat -d 1 or iotop to find the process, then the query, job or backup that reads so much. On cloud volumes, check the provisioned IOPS/throughput and burst balance too.
The USE method
For every resource, check Utilisation, Saturation and Errors (Brendan Gregg's USE method). It turns the tools above into a checklist:
| Resource | Utilisation | Saturation | Errors |
|---|---|---|---|
| CPU | vmstat us+sy, mpstat |
vmstat r > CPUs, load |
dmesg (MCE) |
| Memory | free (available) |
vmstat si/so, PSI, OOM kills |
dmesg |
| Disk | iostat %util |
iostat aqu-sz, await |
dmesg, smartctl |
| Network | sar -n DEV vs link speed |
ss queues, retransmits (nstat) |
ip -s link errors/drops |
Test yourself
A 4-CPU server shows load average 12, but vmstat reports 60% idle CPU and high wa. What is the likely bottleneck?
- CPU
- Disk I/O: Linux load counts tasks in uninterruptible I/O sleep
- The network
- Too many users
Load averages read 0.80, 2.10, 6.40. What does that tell you?
- Load is increasing
- A busy period is over and load is falling; the 15-minute average lags behind
- The server has 6 CPUs
- Nothing
On a cloud VM, vmstat shows st at 30%. What does that mean?
- 30% of CPU is used by the kernel
- The hypervisor gave 30% of this VM's CPU time to others (steal), e.g. a noisy neighbour or exhausted burst credits
- Swap usage
- Network wait