Skip to content
masdzub.com
~/articles/prometheus — one from the notebook

Monitoring Disk I/O Saturation with Prometheus node_exporter and Grafana

Measure disk I/O saturation with node_exporter diskstats, PromQL recording rules, Grafana panels, and alerts that do not page you at 3am for nothing.

masdzub@website:~$ cat ~/articles/using-prometheus-nodeexporter-and-grafana-to-monitor-disk-io-saturation.aspx.md
# 1 file · 22 min read · topic: prometheus · status: published

Introduction

Disk saturation is the one resource you cannot fix by adding more of it at 3am, so you need to see it coming. The practical answer is to stop graphing iowait and instead derive four numbers per block device from /proc/diskstats: utilization, average queue depth, per-request latency, and pressure stall time. node_exporter exposes all the raw counters, Prometheus recording rules turn them into ratios and seconds, and Grafana renders them next to each other so you can tell the difference between a busy disk and a disk that is making your application wait.

This article builds that pipeline end to end: install and verify node_exporter, understand which field of /proc/diskstats maps to which metric, write recording rules that survive counter resets and zero-traffic devices, build a dashboard that does not lie, and write alerts that fire on saturation rather than on utilization. It also covers the parts that bite people in production: NVMe versus SATA accounting, device renaming, cgroup-level I/O, and the kernel accounting quirks that make avgqu-sz from diskstats an approximation rather than a truth.

Utilization is not saturation

A disk at 100 percent utilization is not necessarily a problem. A single-threaded dd with oflag=direct can keep a device busy while delivering 400 IOPS, and nothing else on the box cares. Saturation is the condition where new I/O requests have to wait for service, which means latency rises, queue depth grows, and threads block in D state. Utilization is an input to that story, not the verdict.

The distinction matters because alerting on utilization produces noise. A backup job that pushes a device to 95 percent busy for twenty minutes every night is healthy. A device at 60 percent busy whose p99 write latency tripled is a problem, and utilization alone will never tell you that.

The three signals that do tell you, in order of reliability:

Average queue depth, derived from node_disk_io_time_weighted_seconds_total, tells you how many requests were outstanding on average. For a single spinning disk, anything sustained above roughly 2 means requests are queuing. For an NVMe device with 64 queues, a queue depth of 2 is nothing.

Per-request latency, derived from the time-spent counters divided by the completed-request counters, tells you what the application actually experiences. This is the number that correlates with slow queries and timeouts.

Pressure stall time, from the kernel PSI interface, tells you how much wall-clock time tasks spent stalled on I/O. This is the only signal in the set that is measured from the consumer’s point of view rather than the device’s.

Everything below builds toward a dashboard that shows those three things together.

Install and verify node_exporter

The diskstats collector is enabled by default in every node_exporter release, so the installation is mostly about making sure the process can read the host’s /proc and that you are not scraping a stale version. Use v1.8 or newer; the collector flag names changed in v1.9 and the PSI collector landed in v1.6.

Terminal window
VERSION=1.9.1
cd /tmp
curl -fsSLO "https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/node_exporter-${VERSION}.linux-amd64.tar.gz"
tar xzf "node_exporter-${VERSION}.linux-amd64.tar.gz"
sudo install -m 0755 "node_exporter-${VERSION}.linux-amd64/node_exporter" /usr/local/bin/node_exporter
/usr/local/bin/node_exporter --version

The version output prints the build revision and the Go version, which is what you want in a bug report. Now the unit file. The textfile directory is included here because you will need it later for cgroup metrics.

/etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus node_exporter
Documentation=https://github.com/prometheus/node_exporter
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=node_exporter
Group=node_exporter
ExecStart=/usr/local/bin/node_exporter \
--web.listen-address=:9100 \
--collector.textfile.directory=/var/lib/node_exporter/textfile \
--collector.diskstats.device-exclude="^(ram|loop|fd|dm-|sr)[0-9]*$"
Restart=on-failure
RestartSec=5
NoNewPrivileges=true
ProtectHome=true
ProtectSystem=strict
ReadWritePaths=/var/lib/node_exporter/textfile
[Install]
WantedBy=multi-user.target

Create the user and directory, then start it.

Terminal window
sudo useradd --system --no-create-home --shell /usr/sbin/nologin node_exporter
sudo install -d -o node_exporter -g node_exporter /var/lib/node_exporter/textfile
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
sudo systemctl status node_exporter --no-pager

Verify the metrics exist before touching Prometheus. Do not skip this step; a dashboard built against metric names that are not being scraped wastes an hour of your life.

Terminal window
curl -s localhost:9100/metrics | grep -c '^node_disk_'
curl -s localhost:9100/metrics | grep 'node_disk_io_time_seconds_total'

You should see one line per device, with device="sda", device="nvme0n1", and so on. If the grep returns nothing, the collector is not reading /proc/diskstats and no amount of PromQL will help.

On Docker or Kubernetes the mount path changes and this is the single most common failure. The container needs the host’s proc mounted and the exporter told where to find it.

Terminal window
docker run -d --name node_exporter --net host --pid host \
-v /:/host:ro,rslave \
-v /proc:/host/proc:ro \
-v /sys:/host/sys:ro \
quay.io/prometheus/node-exporter:v1.9.1 \
--path.rootfs=/host \
--path.procfs=/host/proc \
--path.sysfs=/host/sys

The diskstats fields behind the metrics

Every number in this article comes from eleven columns in /proc/diskstats. Knowing the mapping saves you from guessing what a metric means.

Terminal window
awk '{print $3, $4, $6, $8, $10, $12, $13}' /proc/diskstats | head -5

The columns, in kernel order, are: reads completed, reads merged, sectors read, milliseconds reading, writes completed, writes merged, sectors written, milliseconds writing, I/Os currently in progress, milliseconds doing I/O, and weighted milliseconds doing I/O. node_exporter divides the millisecond fields by 1000 and appends _total, so node_disk_io_time_seconds_total is cumulative busy time and node_disk_io_time_weighted_seconds_total is cumulative busy time multiplied by queue depth.

That last one is the useful part. Because the kernel adds queue_depth * elapsed for each accounting tick, the rate of the weighted counter is the time-averaged queue depth. This is exactly what iostat -x reports as avgqu-sz, and if your PromQL and iostat disagree by more than a few percent on the same interval, one of them is looking at a different device or a different window.

The counters you will use:

  • node_disk_io_time_seconds_total for utilization ratio
  • node_disk_io_time_weighted_seconds_total for average queue depth
  • node_disk_read_time_seconds_total and node_disk_write_time_seconds_total for latency
  • node_disk_reads_completed_total and node_disk_writes_completed_total for IOPS
  • node_disk_read_bytes_total and node_disk_written_bytes_total for throughput and average request size
  • node_disk_io_now for the instantaneous in-flight count

Sector counts are multiplied by 512 by the kernel regardless of the device’s physical sector size, which is why node_disk_read_bytes_total is correct even on 4Kn drives. Do not recompute it yourself from sectors.

One caveat that matters for accuracy: the kernel updates these tick-based fields in jiffies, not in nanoseconds, and since Linux 5.0 the accounting batches updates via update_io_ticks. Sub-jiffy bursts can therefore be missed or rounded, and on a device doing very short queue-nonempty intervals the weighted time can drift from reality. For capacity planning that is fine. For microsecond-level latency analysis, use iostat or an eBPF tool, not diskstats.

Prometheus scrape configuration

A single static target is enough for a lab, but production hosts usually need the instance label to be the hostname rather than host:9100, and you want the exporter’s own metrics separated from application metrics.

# /etc/prometheus/prometheus.yml (excerpt)
global:
scrape_interval: 15s
scrape_timeout: 10s
evaluation_interval: 15s
scrape_configs:
- job_name: node
metrics_path: /metrics
static_configs:
- targets:
- db-01.internal:9100
- db-02.internal:9100
- web-01.internal:9100
relabel_configs:
- source_labels: [__address__]
regex: '([^:]+):.*'
target_label: instance
replacement: '$1'
- target_label: env
replacement: production

The 15 second interval is a deliberate compromise. Shorter intervals give you better resolution on bursty I/O but multiply the series count and the storage cost, and since diskstats counters only change when I/O happens, the marginal information gain past 15 seconds is small for capacity work. If you are chasing a specific incident, drop to 5 seconds temporarily via a separate job rather than globally.

Check that the target is up and that the disk metrics are actually ingested.

Terminal window
promtool check config /etc/prometheus/prometheus.yml
curl -s 'http://localhost:9090/api/v1/targets?state=active' | jq -r '.data.activeTargets[] | "\(.labels.instance) \(.health)"'
curl -sG 'http://localhost:9090/api/v1/query' \
--data-urlencode 'query=count by (instance) (node_disk_io_time_seconds_total)' | jq '.data.result'

If the second query returns fewer instances than the first, those hosts are scraping but not exporting disk metrics, which almost always means the container mount problem from the previous section.

Cardinality is worth a thought before you scale. Each device contributes roughly twenty series. A host with four NVMe namespaces, two multipath devices, and eight loop devices contributes far more than you expect, and loop devices are pure noise. The --collector.diskstats.device-exclude regex in the unit file above removes them at the source, which is cheaper than dropping them in Prometheus. In node_exporter v1.9 the old --collector.diskstats.ignored-devices flag was removed, so if you are upgrading from v1.8 or earlier, rewrite it as device-exclude or the service will fail to start.

Recording rules that turn counters into saturation signals

Raw counters are unreadable in a dashboard and expensive to re-evaluate in every panel. Recording rules give you stable names, one place to fix a formula, and a chance to handle the division-by-zero and counter-reset cases once.

/etc/prometheus/rules/disk.rules.yml
groups:
- name: disk-saturation
interval: 15s
rules:
- record: instance_device:disk_utilization:ratio5m
expr: |
rate(node_disk_io_time_seconds_total{device!~"loop.*|ram.*"}[5m])
- record: instance_device:disk_avg_queue_depth:ratio5m
expr: |
rate(node_disk_io_time_weighted_seconds_total{device!~"loop.*|ram.*"}[5m])
- record: instance_device:disk_read_latency:seconds5m
expr: |
(
rate(node_disk_read_time_seconds_total{device!~"loop.*|ram.*"}[5m])
/
rate(node_disk_reads_completed_total{device!~"loop.*|ram.*"}[5m])
) > 0
- record: instance_device:disk_write_latency:seconds5m
expr: |
(
rate(node_disk_write_time_seconds_total{device!~"loop.*|ram.*"}[5m])
/
rate(node_disk_writes_completed_total{device!~"loop.*|ram.*"}[5m])
) > 0
- record: instance_device:disk_read_iops:rate5m
expr: |
rate(node_disk_reads_completed_total{device!~"loop.*|ram.*"}[5m])
- record: instance_device:disk_write_iops:rate5m
expr: |
rate(node_disk_writes_completed_total{device!~"loop.*|ram.*"}[5m])
- record: instance_device:disk_read_size:bytes5m
expr: |
(
rate(node_disk_read_bytes_total{device!~"loop.*|ram.*"}[5m])
/
rate(node_disk_reads_completed_total{device!~"loop.*|ram.*"}[5m])
) > 0

The > 0 filter at the end of the latency rules is not decoration. When a device has zero reads in the window, the division produces NaN and the series either disappears from the panel or renders as a gap. When it has a tiny nonzero number of reads, the division produces a meaningless spike. Filtering on > 0 drops both cases, because NaN > 0 evaluates to false in PromQL.

A caution on the 5 minute window. rate() over 5 minutes at a 15 second scrape interval uses 20 samples, which smooths out the bursts that usually cause incidents. If your application sees sub-minute write stalls, add a second set of rules at [1m] and use those in the alert, keeping the 5 minute version for dashboards and capacity graphs. The 1 minute rate is noisier and will occasionally produce artifacts when a sample lands late, but it reacts fast enough to be useful.

Also resist the urge to compute latency as 1/utilization. It is a common shortcut and it is wrong: busy time divided by busy time is not per-request service time, and the result tells you nothing about how long a request waited.

Building the Grafana dashboard

The dashboard needs three rows: capacity, saturation, and the comparison against what the application feels. Build it with a device variable so the same board works on a laptop and on a 24-disk storage node.

The variable query:

label_values(node_disk_io_time_seconds_total{device!~"loop.*|ram.*"}, device)

Enable multi-value and include an All option. Then every panel filters on device=~"$device".

The utilization panel, as a time series with unit percent (0.0-1.0):

instance_device:disk_utilization:ratio5m{instance=~"$instance", device=~"$device"}

The queue depth panel, unit short, with a threshold line drawn at your device’s comfortable depth. For SATA SSDs that line sits around 4, for spinning disks around 2, for NVMe around 32. Setting it per device class is more honest than picking one number for everything.

instance_device:disk_avg_queue_depth:ratio5m{instance=~"$instance", device=~"$device"}

The latency panel is where most dashboards fall apart, because read and write latency on the same axis hide each other. Split them into two targets and use a log scale on the Y axis, since spinning disk reads and NVMe writes differ by three orders of magnitude.

instance_device:disk_read_latency:seconds5m{instance=~"$instance", device=~"$device"}
instance_device:disk_write_latency:seconds5m{instance=~"$instance", device=~"$device"}

The throughput panel, unit bytes/sec:

rate(node_disk_read_bytes_total{instance=~"$instance", device=~"$device"}[5m])
rate(node_disk_written_bytes_total{instance=~"$instance", device=~"$device"}[5m])

If you prefer to provision the board as code rather than clicking, a minimal panel definition looks like this. The full dashboard JSON is long, but the shape of one panel is what you actually need to copy.

{
"type": "timeseries",
"title": "Average queue depth",
"datasource": { "type": "prometheus", "uid": "prom-main" },
"targets": [
{
"expr": "instance_device:disk_avg_queue_depth:ratio5m{instance=~\"$instance\", device=~\"$device\"}",
"legendFormat": "{{instance}} {{device}}"
}
],
"fieldConfig": {
"defaults": {
"unit": "short",
"custom": { "lineWidth": 2, "fillOpacity": 10, "showPoints": "never" },
"thresholds": {
"mode": "absolute",
"steps": [
{ "color": "green", "value": null },
{ "color": "orange", "value": 4 },
{ "color": "red", "value": 16 }
]
}
},
"overrides": []
}
}

The fourth row is the one that makes the dashboard trustworthy: put PSI stall time on it. If the kernel exposes pressure metrics (node_exporter v1.6 and later, kernel with CONFIG_PSI), this is the closest thing to a ground truth you have.

rate(node_pressure_io_stalled_seconds_total[5m])
rate(node_pressure_io_waiting_seconds_total[5m])

A value of 0.4 on the stalled series means 40 percent of the last five minutes, at least one task was stalled on I/O. When that line rises while utilization sits at 70 percent, you have found a real bottleneck that a utilization-only dashboard would have hidden.

Alerting on saturation without alert fatigue

Alert on the combination of high queue depth and high latency, not on utilization alone, and require the condition to hold long enough that a nightly backup does not wake anyone.

/etc/prometheus/rules/disk.alerts.yml
groups:
- name: disk-alerts
rules:
- alert: DiskIOSaturated
expr: |
(
instance_device:disk_avg_queue_depth:ratio5m > 8
and
instance_device:disk_utilization:ratio5m > 0.90
)
for: 10m
labels:
severity: warning
annotations:
summary: "Disk {{ $labels.device }} on {{ $labels.instance }} is saturated"
description: "Average queue depth {{ $value | printf \"%.2f\" }} with utilization above 90 percent for 10 minutes."
- alert: DiskWriteLatencyHigh
expr: |
instance_device:disk_write_latency:seconds5m > 0.05
and
instance_device:disk_write_iops:rate5m > 50
for: 10m
labels:
severity: warning
annotations:
summary: "Write latency {{ $value | printf \"%.3f\" }}s on {{ $labels.device }} ({{ $labels.instance }})"
- alert: DiskIOStalled
expr: rate(node_pressure_io_stalled_seconds_total[5m]) > 0.30
for: 15m
labels:
severity: critical
annotations:
summary: "{{ $labels.instance }} spends more than 30 percent of time stalled on I/O"
- alert: DiskFillingUp
expr: |
predict_linear(node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"}[6h], 86400) < 0
and
node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} < 20 * 1024 * 1024 * 1024
for: 1h
labels:
severity: warning
annotations:
summary: "{{ $labels.mountpoint }} on {{ $labels.instance }} predicted full within 24h"

The IOPS floor in the latency alert exists because latency on a device doing two writes per second is statistically meaningless and will flap. Requiring at least 50 IOPS before the alert can fire removes most of that noise.

The queue depth threshold of 8 is a starting point, not a law. Tune it per device class using a recording rule that carries a device-class label, or accept a single conservative number and rely on the for: 10m clause to suppress transients. What you should not do is set it to 1 because that is what a textbook says about single disks; a modern NVMe device routinely runs at queue depth 20 without any application noticing.

The stall alert is the one worth paging on. It is measured from the scheduler’s perspective, it fires when tasks are actually blocked, and it does not care whether the cause is one hot device, a full page cache, or a runaway rsync.

Per-cgroup and per-process I/O with the textfile collector

Node-level numbers tell you a device is saturated. They do not tell you which service did it. On cgroup v2 systems, /sys/fs/cgroup/.../io.stat gives per-cgroup byte and operation counters, and the textfile collector lets you publish them through node_exporter without writing a custom exporter.

/usr/local/bin/cgroup-io-metrics.sh
#!/bin/bash
set -euo pipefail
outdir=/var/lib/node_exporter/textfile
out="${outdir}/cgroup_io.prom"
tmp="${out}.$$"
: > "$tmp"
shopt -s nullglob
for stat in /sys/fs/cgroup/system.slice/*.service/io.stat; do
unit=$(basename "$(dirname "$stat")" .service)
awk -v unit="$unit" '
NF > 1 {
dev = $1
for (i = 2; i <= NF; i++) {
split($i, kv, "=")
printf "cgroup_io_%s{unit=\"%s\",device=\"%s\"} %s\n", kv[1], unit, dev, kv[2]
}
}
' "$stat" >> "$tmp"
done
mv "$tmp" "$out"

The atomic mv matters: the textfile collector reads whatever is on disk, so a partially written file produces a scrape with half the series and a rate() gap. Writing to a temp file in the same directory and renaming is atomic on any normal filesystem.

Run it from a timer:

/etc/systemd/system/cgroup-io-metrics.service
[Unit]
Description=Export cgroup v2 io.stat to node_exporter textfile collector
[Service]
Type=oneshot
ExecStart=/usr/local/bin/cgroup-io-metrics.sh
/etc/systemd/system/cgroup-io-metrics.timer
[Unit]
Description=Refresh cgroup io metrics every 15s
[Timer]
OnBootSec=15s
OnUnitActiveSec=15s
AccuracySec=1s
[Install]
WantedBy=timers.target
Terminal window
sudo chmod 0755 /usr/local/bin/cgroup-io-metrics.sh
sudo systemctl daemon-reload
sudo systemctl enable --now cgroup-io-metrics.timer
sudo -u node_exporter /usr/local/bin/cgroup-io-metrics.sh
ls -l /var/lib/node_exporter/textfile/

Then attribute write throughput per unit:

rate(cgroup_io_wbytes{unit=~"$unit"}[5m])

Two limitations are worth stating plainly. First, cgroup v2 io.stat only accounts I/O that goes through the cgroup’s own path; buffered writes are charged to the cgroup that dirtied the page, but the actual writeback can happen later and appears in the node-level device counters, not necessarily where you expect. Second, io.stat reports zero for devices that use iocost without proper configuration on some kernels, so validate against the node-level totals before trusting the split.

If you need per-process rather than per-cgroup, use process-exporter with a config that matches on comm, or use eBPF-based biolatency and biosnoop from bcc for one-off investigations. Neither belongs in a Prometheus pipeline for continuous monitoring.

Device naming, NVMe, and kernel accounting caveats

/dev/sda is not a stable identifier. On a host with a SAN, multipath, and hotplug, the same LUN can appear as sdb today and sdc after a reboot, which silently breaks every dashboard and alert keyed on the device label. The fix is a udev rule that creates a stable symlink, then teaching node_exporter to use it.

/etc/udev/rules.d/60-persistent-io.rules
KERNEL=="sd*[!0-9]|nvme[0-9]*n[0-9]*", SUBSYSTEM=="block", \
ENV{ID_SERIAL_SHORT}!="", SYMLINK+="io-$env{ID_SERIAL_SHORT}"

Reload and confirm:

Terminal window
sudo udevadm control --reload-rules
sudo udevadm trigger --subsystem-match=block
ls -l /dev/io-*

node_exporter does not follow these symlinks by default; the diskstats collector reads /proc/diskstats, which only has kernel names. So the stable label has to come from Prometheus relabeling against a mapping, or from an instance_device naming convention you enforce in the recording rule. The pragmatic option most teams land on is to keep the kernel name but pin the hardware with a documented inventory, and accept that a disk replacement means a dashboard rename.

NVMe behaves differently from SATA in ways that matter for interpretation. An NVMe device has multiple hardware queues, and /proc/diskstats aggregates across all of them, so the reported queue depth is the sum over queues rather than the depth of any single one. The kernel also reports discard operations separately since 5.5, which means node_disk_io_time_seconds_total on older kernels misses discard time entirely. If you run fstrim on a schedule and see utilization drop to zero while the trim runs, that is the accounting gap, not a bug in your query.

Virtual machines add another layer. A virtio disk reports queue depth from the guest’s perspective, which is the depth the guest submitted, not the depth the host storage array is experiencing. On a noisy-neighbour hypervisor the guest can show a queue depth of 1 and 200ms latency, because the saturation lives outside the guest entirely. In that case the PSI stall metric is the only signal that still points at the truth.

Troubleshooting

These are the failures that show up repeatedly when this stack is built for the first time.

Exporter is not reachable at all:

curl: (7) Failed to connect to localhost port 9100 after 0 ms: Couldn't connect to server

The service is not running, or it is bound to a different address. Check systemctl status node_exporter --no-pager, then journalctl -u node_exporter -n 50 --no-pager, then ss -ltnp | grep 9100. A common cause is a port collision with another exporter, which shows up as listen tcp :9100: bind: address already in use in the journal.

Collector fails inside a container:

level=error msg="ERROR: diskstats collector failed after 0.000152s: open /host/proc/diskstats: no such file or directory" source="collector.go:169"

The host proc is not mounted where the exporter expects. Mount /proc at /host/proc read-only and pass --path.procfs=/host/proc. The same error with /proc/diskstats instead of /host/proc/diskstats means the container has no proc mount at all, which happens with restrictive security policies.

Prometheus target is down with a timeout:

Get "http://db-01.internal:9100/metrics": context deadline exceeded

Either the scrape timeout is too short for a host under heavy I/O (the exporter itself can be starved), or a firewall is dropping packets without rejecting them. Test from the Prometheus host with curl -m 5 -v http://db-01.internal:9100/metrics to separate the two cases.

Recording rule fails to load:

level=error component=rule-manager err="loading groups failed: group \"disk-saturation\", rule 3, \"instance_device:disk_write_latency:seconds5m\": could not parse expression: 1:120: parse error: unclosed left parenthesis"

PromQL parse errors are almost always a mismatched parenthesis across the multi-line expr block, usually introduced by editing one side of the division. Run promtool check rules /etc/prometheus/rules/disk.rules.yml before reloading; it catches this in under a second.

Metric disappeared after an upgrade:

Error: unknown long flag '--collector.diskstats.ignored-devices'

That flag was removed in node_exporter v1.9 in favour of --collector.diskstats.device-exclude. Replace it and restart. The service will not start until the flag is corrected, which is why the target goes down immediately after the package upgrade.

Grafana panel shows “No data” while the query works in the Prometheus UI:

Datasource prometheus was not found

The dashboard JSON references a datasource UID that does not exist in this Grafana instance. Re-select the datasource in the panel editor, or export the dashboard with ${DS_PROMETHEUS} templating so it resolves on import.

Latency panel shows absurd values like 47 seconds:

node_disk_write_time_seconds_total is 0 on a device that clearly writes

The device is a stacked device (LVM, dm-crypt, or md) whose underlying physical device carries the timing, or the kernel does not populate the time fields for that driver. Check /proc/diskstats directly with awk '{print $3, $8, $12}' and compare against iostat -x 1 for the same device. If the raw field is zero, no query will recover it.

Duplicate series after adding a recording rule:

vector contains metrics with the same labelset after applying rule labels

Two rules produce the same metric name and label set, usually because a copy-paste left the old rule in place alongside the new one. Grep the rules directory for the metric name and delete the stale block.

Case study: the database host with 90 percent iowait

Consider a representative PostgreSQL host, 16 cores, one NVMe data device, and a 20 minute window where iowait sits at 90 percent and every query is slow. This is the scenario that motivates the whole pipeline, and the numbers below are an illustration of the pattern rather than a measurement from a specific machine.

iowait at 90 percent looks catastrophic and tells you almost nothing. It is the percentage of CPU time where the CPU was idle and at least one task was blocked on I/O. On a machine with 16 cores and a single-threaded workload, one blocked task can push iowait to 6 percent, and the number becomes meaningless as a saturation indicator once you have many cores.

The dashboard tells a different story. Utilization on nvme0n1 reads 0.98, which alone would suggest a bottleneck. Average queue depth reads 1.4, which for an NVMe device with 64 queues means the device is barely working. Write latency reads 0.3ms, which is normal for that hardware. PSI stalled time reads 0.02, meaning tasks spent 2 percent of the window waiting on I/O.

Four signals, three of which say the device is fine. The conclusion is that the NVMe is busy but not saturated, and the slow queries are caused by something else: lock contention, a missing index, or a connection pool exhausted by a long-running transaction. The utilization graph was the misleading one, and the queue depth plus latency plus stall combination was the correction.

Now change one number. Queue depth reads 28, write latency reads 12ms, PSI stalled reads 0.45. Utilization is still 0.98. This time the device is genuinely saturated, the application is waiting, and the alert on DiskIOSaturated should have fired ten minutes ago. The same utilization value, two completely different situations, which is the entire argument for not alerting on utilization.

The practical lesson is to put queue depth and latency on the same row as utilization in the dashboard, always, so that nobody ever looks at the utilization graph in isolation and draws the wrong conclusion.

What this setup does not tell you

Diskstats are aggregated at the device level and that aggregation loses information you sometimes need. It cannot distinguish a random read workload from a sequential one, so two hosts with identical queue depth can have wildly different application performance. It cannot tell you which file or which table is responsible. And it cannot see the storage array or the network fabric behind a SAN LUN, where the real saturation usually lives.

For those questions you need a different tool: biolatency and biosnoop from bcc for per-request tracing, filetop for per-file I/O, or the storage vendor’s own telemetry for the array. Prometheus is the right place for trends, capacity, and alerting; it is the wrong place for a one-off investigation into which query is hammering the disk.

Two more gaps are worth knowing about before you trust the dashboard. First, the device-level counters include readahead and writeback traffic that no application requested, so a host with a large page cache can show heavy write throughput with no corresponding application writes. Second, container filesystems on overlay or device-mapper add a layer that splits a single application write into multiple device writes, which inflates IOPS relative to what the application issued.

None of these gaps invalidate the pipeline. They just define its scope: it answers whether the device is a bottleneck and whether the trend is getting worse. It does not answer why. Pair it with a latency-aware APM and per-cgroup attribution, and you have enough to diagnose the majority of real incidents without guessing.

found this useful? share it →
Written by

Dzubayyan Ahmad

System Administrator, SRE & Technical Support Engineer specialising in web hosting infrastructure — Linux servers, automation, and monitoring. Writing these notes since 2015 so future-me can find the fix again.