Skip to content

Monitor NVMe SSD wear and health with nvme-cli before a drive goes read-only

How to read the NVMe SMART/health log with nvme-cli, interpret percentage_used, available_spare, media_errors and critical_warning, check Data Units Written against the rated TBW, and alert on wear thresholds so drives get replaced on schedule.

nvme smart-log /dev/nvme0 answers the whole question in one screen. percentage_used is how much of the rated write endurance the controller thinks you have burned. available_spare is the percentage of reserve blocks still unused. critical_warning is a bitmask the drive raises when it has already decided something is wrong. media_errors counts data it could not return. There is no vendor attribute table to sift through the way there is on SATA — NVMe defines these fields in the specification, so every drive reports the same names with the same meanings. This guide covers reading them correctly, converting Data Units Written into terabytes so you can compare it against the drive’s rated TBW, checking the endurance group log where one exists, and wiring a threshold alert so a worn drive gets swapped during a maintenance window instead of dropping itself into read-only mode on a Tuesday afternoon.

What you’ll accomplish

  • Read the NVMe SMART/health log on every drive in a host and know which four fields carry the signal.
  • Decode critical_warning bit by bit, so a non-zero value turns into a specific fault rather than a vague alarm.
  • Convert Data Units Written into real terabytes and compare it against the drive’s rated endurance, which no drive reports about itself.
  • Export the health fields as Prometheus metrics and alert on wear thresholds you choose, not on the drive’s own end-of-life bit.
  • Know where NVMe health data is unavailable — cloud volumes, virtio guests, drives behind a RAID controller — so you stop looking for it there.

Prerequisites

  • nvme-cli 2.0 or newer. Debian 12 ships 2.3, Ubuntu 24.04 ships 2.8, RHEL 9 ships 2.2. The 1.x series prints the same fields with slightly different labels and its JSON output is shaped differently, which matters once you script it. Install with apt install nvme-cli or dnf install nvme-cli.
  • Root or sudo. Every admin command goes to the device through an ioctl that requires raw access.
  • The right device node. /dev/nvme0 is the controller, /dev/nvme0n1 is a namespace on it. Health commands accept either; the log page belongs to the controller regardless of which one you name.
  • A physical NVMe device. A guest with a virtio-blk or virtio-scsi disk has no NVMe controller to ask, and an attached cloud block volume is not NVMe media even when the guest calls it /dev/nvme1n1. Only a bare-metal host, or a guest with the controller passed through with vfio-pci, sees real health data.
  • The drive’s rated TBW or DWPD figure, from the datasheet. The drive does not report it, and percentage_used alone will not tell you how many terabytes you have left.
  • jq and a Prometheus setup for the alerting steps. Anything that can run a script on a schedule works; the example uses the node_exporter textfile collector.

How it works

An NVMe controller keeps its own counters in firmware and exposes them through log pages. nvme-cli sends a Get Log Page admin command down to the device through the character device node and formats whatever comes back. Nothing in the kernel computes these numbers — it only carries the request and the 512-byte response.

Diagram showing nvme-cli commands passing through the Linux character device and admin passthrough ioctl to the SSD controller log pages, and the four SMART health fields that drive replacement decisions

Log page 0x02 is the SMART/Health Information log, and it is the one you want. Log page 0x01 holds the error information log. Log page 0x09, present on drives that implement endurance groups, reports the same wear picture aggregated across a set of namespaces.

Three details in that log page trip people up.

Data Units Written is not bytes and not sectors. One data unit is 1,000 blocks of 512 bytes, so 512,000 bytes exactly. Newer nvme-cli builds print the converted figure in parentheses; older ones do not, and you multiply by hand.

percentage_used is the vendor’s estimate, not a measurement of your writes. It accounts for write amplification, block erase counts and whatever else the firmware weighs, so it usually runs ahead of the ratio you get by dividing host bytes written by rated TBW. It can also exceed 100 % — the specification caps the reported value at 255, and a drive past 100 % is past its warranted endurance, not dead.

available_spare is a percentage, and it only means something next to available_spare_threshold, which is a per-drive value the firmware sets, commonly 10 %. When the spare falls to the threshold, the drive sets bit 0 of critical_warning. That is the last warning you get before the controller may put the media into read-only mode, and by then you are reacting rather than planning.

Step-by-step

1. Enumerate the NVMe devices on the host. nvme list shows namespaces, models, firmware revisions and serial numbers in one table:

sudo nvme list
Node                  Generic               SN                   Model                                    Namespace  Usage                      Format           FW Rev
--------------------- --------------------- -------------------- ---------------------------------------- ---------- -------------------------- ---------------- --------
/dev/nvme0n1          /dev/ng0n1            S64ANE0R123456       Samsung SSD 980 PRO 2TB                  0x1          1.24  TB /   2.00  TB    512   B +  0 B   5B2QGXA7
/dev/nvme1n1          /dev/ng1n1            PHLJ1180047K1P0I     INTEL SSDPE2KX010T8                      0x1        780.11 GB /   1.00  TB      4 KiB +  0 B   VDV10184

If a drive you know is installed is missing here, the kernel never bound it — check lspci -nn | grep -i nvme and dmesg | grep nvme before going any further.

2. Read the health log. This is the command the rest of the guide revolves around:

sudo nvme smart-log /dev/nvme0
Smart Log for NVME device:nvme0 namespace-id:ffffffff
critical_warning			: 0
temperature				: 41 °C (314 K)
available_spare				: 100%
available_spare_threshold		: 10%
percentage_used				: 7%
endurance group critical warning summary: 0
Data Units Read				: 84,321,556 (43.17 TB)
Data Units Written			: 118,204,442 (60.52 TB)
host_read_commands			: 1,943,208,771
host_write_commands			: 2,884,110,265
controller_busy_time			: 14,209
power_cycles				: 47
power_on_hours				: 21,884
unsafe_shutdowns			: 9
media_errors				: 0
num_err_log_entries			: 0
Warning Temperature Time		: 0
Critical Composite Temperature Time	: 0
Temperature Sensor 1			: 41 °C (314 K)
Temperature Sensor 2			: 47 °C (320 K)

That drive is healthy: no warning bits, full spare capacity, 7 % of rated endurance consumed after two and a half years of power-on time, no media errors.

3. Decode critical_warning when it is not zero. The field is a bitmask, and each bit is a different problem:

sudo nvme smart-log /dev/nvme0 | grep critical_warning
critical_warning			: 0x1
  • Bit 0 (0x01) — available spare has fallen to or below the threshold.
  • Bit 1 (0x02) — temperature is past a warning or critical limit.
  • Bit 2 (0x04) — the NVM subsystem reliability is degraded because of media or internal errors.
  • Bit 3 (0x08) — the media has been placed in read-only mode. The drive will not accept writes again.
  • Bit 4 (0x10) — the volatile memory backup device failed, on drives that have one.
  • Bit 5 (0x20) — a persistent memory region is read-only or unreliable.

Bit 3 is the outcome this whole exercise exists to avoid. When it is set, the drive is a source for a copy and nothing else.

4. Convert Data Units Written into terabytes. Older nvme-cli builds omit the parenthesised conversion, and scripts should not parse it anyway:

sudo nvme smart-log /dev/nvme0 -o json | jq '.data_units_written * 512000 / 1e12'
60.52067430

Now compare that against the datasheet. A 2 TB consumer drive rated at 1,200 TBW is 5.0 % consumed by host writes, while percentage_used reports 7 %. The gap is write amplification, and the controller’s number is the one to trust — it sees the erases you do not.

Where endurance is quoted as DWPD, multiply drive writes per day by capacity in TB by 365 by the warranty years: a 1 TB drive at 1 DWPD over 5 years is 1,825 TBW.

5. Track available_spare against its threshold. Reserve blocks are how the drive absorbs failing NAND. A spare percentage that has left 100 % is the first physical evidence of wear, and it is a stronger signal than percentage_used because it reflects actual block failures rather than an estimate:

sudo nvme smart-log /dev/nvme0 -o json | jq '{spare: .avail_spare, threshold: .spare_thresh, used: .percent_used}'
{
  "spare": 100,
  "threshold": 10,
  "used": 7
}

Note the abbreviated key names in JSON output — avail_spare, spare_thresh, percent_used — which differ from the labels in the human-readable table.

Diagram of four NVMe wear stages from a fresh drive through steady wear, a warning band and end of life, with the readings and the action each stage should trigger

6. Read the error information log. media_errors counts events; the error log tells you what they were:

sudo nvme error-log /dev/nvme0 -e 3
Error Log Entries for device:nvme0 entries:3
.................
 Entry[ 0]
.................
error_count	: 12
sqid		: 3
cmdid		: 0x400c
status_field	: 0x2802(UNRECOVERED_READ_ERROR: The read data could not be recovered from the media)
lba		: 1953504368
nsid		: 0x1
.................

Most drives return a full ring buffer of empty entries with error_count: 0. Entries with a real status_field and a plausible lba are what matter, and an UNRECOVERED_READ_ERROR means a host read failed — data loss you should already be seeing in filesystem logs.

7. Check the endurance group log, if the drive has one. Enterprise drives that group namespaces report wear per group rather than per controller:

sudo nvme endurance-log /dev/nvme0 -g 1
Endurance Group Log for NVME device:nvme0 Group ID:1
critical warning			: 0
avl_spare				: 100
avl_spare_threshold			: 10
percent_used				: 4
endurance_estimate			: 1800
data_units_read				: 41230118
data_units_written			: 62884210
media_units_written			: 71204338

endurance_estimate is the rated endurance in units of 1,000,000 data units — the only place a drive tells you its own TBW budget. Drives without endurance groups return Invalid Field in Command, which is not an error on your part.

8. Confirm the controller’s own limits. nvme id-ctrl reports warning and critical composite temperature thresholds, which is what critical_warning bit 1 fires against:

sudo nvme id-ctrl /dev/nvme0 -H | grep -E '^(wctemp|cctemp|tnvmcap)'
wctemp    : 358
cctemp    : 358
tnvmcap   : 2000398934016

Temperatures are in kelvin: 358 K is 85 °C. tnvmcap is total capacity in bytes.

9. Export the fields as Prometheus metrics. A short script and the node_exporter textfile collector are enough — see the node_exporter setup guide if the collector directory does not exist yet:

sudo tee /usr/local/bin/nvme-health-metrics.sh >/dev/null <<'EOF'
#!/bin/bash
# Write NVMe health fields for the node_exporter textfile collector.
set -euo pipefail
OUT=/var/lib/node_exporter/textfile_collector/nvme_health.prom
TMP=$(mktemp "${OUT}.XXXXXX")

echo '# TYPE nvme_critical_warning gauge' >> "$TMP"
echo '# TYPE nvme_available_spare_percent gauge' >> "$TMP"
echo '# TYPE nvme_available_spare_threshold_percent gauge' >> "$TMP"
echo '# TYPE nvme_percentage_used_percent gauge' >> "$TMP"
echo '# TYPE nvme_media_errors_total counter' >> "$TMP"
echo '# TYPE nvme_data_units_written_total counter' >> "$TMP"

for dev in /dev/nvme[0-9]n[0-9]; do
  [ -e "$dev" ] || continue
  d=$(basename "$dev")
  nvme smart-log "$dev" -o json | jq -r --arg d "$d" '
    (.critical_warning | if type == "object" then .value else . end) as $cw |
    "nvme_critical_warning{device=\"\($d)\"} \($cw)",
    "nvme_available_spare_percent{device=\"\($d)\"} \(.avail_spare)",
    "nvme_available_spare_threshold_percent{device=\"\($d)\"} \(.spare_thresh)",
    "nvme_percentage_used_percent{device=\"\($d)\"} \(.percent_used)",
    "nvme_media_errors_total{device=\"\($d)\"} \(.media_errors)",
    "nvme_data_units_written_total{device=\"\($d)\"} \(.data_units_written)"
  ' >> "$TMP"
done

chmod 644 "$TMP"
mv "$TMP" "$OUT"
EOF
sudo chmod 755 /usr/local/bin/nvme-health-metrics.sh

The if type == "object" branch is not defensive padding. nvme-cli changed critical_warning in JSON from a plain integer to an object with a value key part way through the 2.x series, and a script that assumes one shape breaks silently on the other.

10. Run it on a timer. Health fields move over weeks, so every fifteen minutes is generous:

sudo systemd-run --on-calendar='*:0/15' --unit=nvme-health /usr/local/bin/nvme-health-metrics.sh
Running timer as unit: nvme-health.timer
Will run service as unit: nvme-health.service

For a permanent installation write the .service and .timer units to /etc/systemd/system/ instead — systemd-run units are transient and vanish on reboot.

11. Write the alerting rules. Pick thresholds that leave you time to order and install a drive, not thresholds that fire when the drive is already finished:

groups:
  - name: nvme-wear
    rules:
      - alert: NvmeCriticalWarning
        expr: nvme_critical_warning > 0
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: 'NVMe {{ $labels.device }} on {{ $labels.instance }} raised a critical warning bit'
      - alert: NvmeSpareNearThreshold
        expr: nvme_available_spare_percent <= nvme_available_spare_threshold_percent + 10
        for: 1h
        labels:
          severity: warning
      - alert: NvmeWearHigh
        expr: nvme_percentage_used_percent >= 80
        for: 6h
        labels:
          severity: warning
      - alert: NvmeMediaErrors
        expr: increase(nvme_media_errors_total[24h]) > 0
        labels:
          severity: warning

Validate it works

Confirm the metrics file is being written with plausible values:

sudo /usr/local/bin/nvme-health-metrics.sh && \
  cat /var/lib/node_exporter/textfile_collector/nvme_health.prom
# TYPE nvme_critical_warning gauge
# TYPE nvme_available_spare_percent gauge
nvme_critical_warning{device="nvme0n1"} 0
nvme_available_spare_percent{device="nvme0n1"} 100
nvme_available_spare_threshold_percent{device="nvme0n1"} 10
nvme_percentage_used_percent{device="nvme0n1"} 7
nvme_media_errors_total{device="nvme0n1"} 0
nvme_data_units_written_total{device="nvme0n1"} 118204442

Confirm node_exporter is publishing them:

curl -s localhost:9100/metrics | grep '^nvme_percentage_used_percent'
nvme_percentage_used_percent{device="nvme0n1"} 7

Confirm the timer will keep running it:

systemctl list-timers nvme-health --all

Prove the alert path end to end by temporarily lowering the NvmeWearHigh threshold below your current percentage_used, reloading Prometheus, and watching the alert reach the receiver. Put the real threshold back afterwards.

Troubleshooting

  • Invalid Field in Command from nvme endurance-log. The drive does not implement endurance groups, or the group ID is wrong. Check nvme id-ctrl /dev/nvme0 -H | grep -i endurance first; most client and many datacentre drives return nothing useful here, and the SMART/health log is the whole story on those.
  • percentage_used sits at 0 % on a drive that has clearly been written to. Some firmware only updates the estimate in coarse steps, and some reports zero until several percent of endurance is gone. Trend data_units_written instead — it moves continuously and is directly comparable to the datasheet.
  • A cloud instance shows /dev/nvme0n1 but smart-log returns nonsense or fails. Attached cloud volumes are frequently presented over an NVMe interface without being NVMe media. The controller you are querying is a virtualisation shim, and the numbers it returns describe nothing physical. Use the provider’s volume status API instead.
  • The JSON script produces empty or malformed metric lines. Run nvme smart-log /dev/nvme0 -o json | jq .critical_warning by hand. If it returns an object, the object branch is being taken; if the whole command errors, the nvme-cli version predates JSON output and you need the human-readable parser or a newer package.
  • nvme list shows the drive but the health log times out. A controller that has stopped answering admin commands is usually already gone. Check dmesg for nvme nvme0: I/O tag ... timeout, reset controller and treat it as a failing device, not a monitoring problem. Firmware updates through nvme fw-download and nvme fw-commit fix a surprising number of these on datacentre drives, but only if the vendor has published one for your exact revision.

When this is the wrong approach

  • Cloud block storage has no wear to monitor. On an attached volume the provider owns the media, replaces it on their schedule, and gives you a volume status field instead of a health log. Monitoring latency and I/O errors is the useful signal there. If you are choosing between instance-local NVMe and attached volumes in the first place, the trade-offs are worth reading through before you build monitoring for either.
  • Drives behind a hardware RAID controller are invisible. The controller presents a virtual disk and keeps the members to itself, so there is no /dev/nvme* node to query. Some controllers expose member health through their own tooling (storcli, perccli); otherwise the controller’s own alerting is what you have.
  • smartctl already does this if you only want a summary. smartctl -a /dev/nvme0 reads the same log page 0x02 and prints the same fields with friendlier labels, and smartd will email on them without any of the scripting above. Reach for nvme-cli when you need the error log, endurance groups, vendor plugin logs, or JSON that scripts cleanly — otherwise the smartctl route is less work.
  • Wear monitoring is not a replacement for redundancy. Controllers fail outright, firmware has bugs, and power events kill drives with every counter reading clean. Wear monitoring tells you when a drive will finish its rated life, which is one failure mode out of several. Backups and mirroring cover the rest.

The field definitions come straight from the NVM Express specifications, and the command reference for every subcommand used here lives in the nvme-cli repository. Vendor plugins add extended logs on top — nvme intel smart-log-add /dev/nvme0 on Intel and Solidigm drives, for example, exposes wear levelling and timed workload counters that the standard log page does not carry.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.