Skip to content

Add opt-in SATA Phy Event Counters collection - #422

Open
jhoblitt wants to merge 1 commit into
prometheus-community:masterfrom
jhoblitt:sata-phy-event-counters
Open

jhoblitt wants to merge 1 commit into
prometheus-community:masterfrom
jhoblitt:sata-phy-event-counters

Conversation

@jhoblitt

Copy link
Copy Markdown

Motivation

SATA link CRC/COMRESET errors point at cables, backplanes and HBAs rather than media, and the drive records them in the SATA Phy Event Counters log. The collector already parsed that log, but smartctl was never asked for it (one of the logs in #92).

What changed

Opt-in --smartctl.sata-phy-log passes --log=sataphy, exported as smartctl_device_sata_phy_events_total{device,id,event} for ATA devices.

Notable decisions

A dedicated counter replaces the never-reachable smartctl_device_statistics rows: smartctl names every vendor-specific counter identically, so only the id label keeps series unique. Orthogonal to #410.


This PR was prepared with an AI coding assistant (Claude Code) at my direction; I own it.

smartctl can print the SATA Phy Event Counters log (GP log 0x11),
whose link-level counters (ICRC errors, COMRESETs, CRC errors in
host-to-device FISes, ...) help to tell failing cables, backplanes and
HBAs from failing disks. smartctl is only asked for it with
--log=sataphy, which the exporter never passed (see prometheus-community#92 about logs
smartctl is not asked for).

Add --smartctl.sata-phy-log (default false). When set, --log=sataphy is
appended to the smartctl arguments before --device, and the counters are
exported for ATA devices as smartctl_device_sata_phy_events_total, a
counter labelled with device, id (the decimal counter id) and event
(smartctl's name for it). It is opt-in because it costs an extra log
read per ATA device and poll. prometheus-community#410 (ATA SSD device statistics with
--log=devstat,7) is orthogonal and follows the same opt-in pattern.

The code that exported these counters through smartctl_device_statistics
never ran, as nothing requested the log, so no such series ever existed
and it is replaced rather than kept. It labelled counters by name only,
but smartctl names every vendor specific counter "Vendor specific" and
every unlisted id "Unknown". A drive reporting two of them would produce
duplicate label sets, which fail Gather() and turn the whole scrape into
an HTTP 500. The new metric adds the id label to keep series unique, and
skips a repeated id. A counter that smartctl flags as overflowed has
reached its maximum and stays there; its value is still exported and the
metric help says so.

Facts checked in smartmontools 7.0 to 7.5: the JSON output, and with it
sata_phy_event_counters, exists since 7.0. Whether the log is available
comes from the drive's IDENTIFY data: unless the GP log directory has
been read (the exporter does not request it), smartctl proceeds only if
IDENTIFY word 76 reports phy event counter support. Otherwise it prints
"SATA Phy Event Counters (GP Log 0x11) not supported" and sets no exit
status bit; the option is ignored for SCSI and NVMe devices. Only a
failed read of the log sets bit 2 of the exit status, which the exporter
logs as a warning and reports in smartctl_device_smartctl_exit_status.

Tests cover the rendering of a real smartctl 7.4 capture of a SATA hard
disk, duplicate "Vendor specific"/"Unknown" names and ids, the ATA-only
gate in Collect(), the descriptor being sent by Describe(), and the
smartctl argument wiring using a fake smartctl. go.mod gains the
indirect godebug dependency required by prometheus/testutil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Joshua Hoblitt <josh@hoblitt.com>
@jhoblitt
jhoblitt marked this pull request as ready for review November 30, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant