iostat - Cheatsheet Statistiche CPU e Disk I/O
iostat riporta utilizzo CPU e statistiche disk I/O per-device — throughput, IOPS, request latency, e queue depth. È il primo stop standard per diagnosticare colli di bottiglia di storage su Linux: il disco è saturo, le richieste sono in coda, la latenza sta salendo? Viene fornito come parte del package sysstat insieme a mpstat, pidstat, e sar.
Installazione
| Piattaforma | Comando |
|---|
| Debian/Ubuntu | sudo apt install sysstat |
| Fedora/RHEL | sudo dnf install sysstat |
| Arch Linux | sudo pacman -S sysstat |
| macOS | iostat è built in (output diverso) |
| Verifica | iostat -V |
Utilizzo di Base
| Comando | Descrizione |
|---|
iostat | Un report da boot (CPU + devices) |
iostat 2 | Refresh ogni 2 secondi |
iostat 2 5 | 5 report, 2 secondi apart |
iostat -x | Extended stats (quelli utili) |
iostat -d | Device stats solamente (no CPU) |
iostat -c | CPU stats solamente |
Il Comando che Effettivamente Vuoi
# Extended, human-readable, per-device, ogni 2s
iostat -xmt 2
| Flag | Effetto |
|---|
-x | Extended statistics (util%, await, aqu-sz, …) |
-m | Riporta in MB/s (usa -k per KB/s) |
-t | Stampa un timestamp con ogni report |
-p DEV | Mostra partizioni di un device (e.g. -p sda) |
-d 2 | Device report ogni 2 secondi |
-h | Human-readable, NVMe-friendly formatting |
Leggere l”Output Extended (-x)
| Colonna | Significato |
|---|
r/s, w/s | Read/write requests al secondo (IOPS) |
rMB/s, wMB/s | Read/write throughput |
rareq-sz / wareq-sz | Dimensione media request |
r_await, w_await | Avg read/write latency (ms) — metrica chiave |
aqu-sz | Profondità media coda (richieste in volo) |
%util | Frazione di tempo il device era busy |
Interpretare i Segnali
| Osservazione | Interpretazione |
|---|
%util vicino al 100% | Device saturo (attento su SSD/NVMe — può parallelizzare) |
Alto await (decine ms+) | Le richieste sono lente — collo di bottiglia latenza |
Alto aqu-sz | Le richieste si accumulano più velocemente di quelle che il disco drena |
| Alto IOPS, basso throughput | Piccolo random I/O (tipico workload DB/metadata) |
| Basso IOPS, alto throughput | Grande sequential I/O (backups, streaming) |
Su modern SSD/NVMe, %util può leggere 100% mentre il device ha ancora headroom (serve le richieste in parallelo). Trusted await e aqu-sz più di %util lì.
Sezione CPU
| Field | Significato |
|---|
%user / %nice | Tempo in user space |
%system | Tempo nel kernel |
%iowait | CPU idle in attesa su I/O (storage pressure hint) |
%steal | Tempo rubato dall”hypervisor (noisy neighbors) |
%idle | Tempo idle |
Alto %iowait insieme a alto disk await punta direttamente allo storage come collo di bottiglia.
Workflow Comuni
# Osserva un sospetto collo di bottiglia disk in tempo reale
iostat -xmt 2
# Focalizza su un device e le sue partizioni
iostat -xmt -p nvme0n1 2
# Correla CPU iowait con device latency durante un load test
iostat -xmt 1 60 > iostat.log
| Tool | Focus |
|---|
| iostat | Per-device I/O + CPU stats |
| iotop | Quale processo sta facendo l”I/O |
| dstat/dool | Combined CPU/disk/net in una vista |
| sar | Storical/recorded system activity |
Usa iostat per vedere il device è lento, poi iotop per trovare quale processo è responsabile.
Risorse