feat(monitoring): NAS storage health alerts (#10) #14

Manually merged
bryan merged 3 commits from n10-5-nas-storage-health into main 2026-11-10 17:30:26 +00:00
Owner

Part of #10 (piece N10.5): alert rules for NAS storage health.

What changes

A new module, services.nas-storage-health, alerts on NAS storage faults from two signals. Neither relies on the filesystem's read-only flag, which can lag a failed pool.

  • btrfs error counters. The NAS's node_exporter (the existing unraid-node job) exports per-device btrfs error counters. NasBtrfsDeviceErrors (critical) fires on any increase over 30 minutes, per device and error type; counts that are already there never fire. NasBtrfsMetricsMissing (warning) covers the collector failing, or a filesystem seen in the last day vanishing while the exporter is up.
  • A write probe. A user LaunchAgent (org.nixos.nas-write-probe, every 10 minutes) runs scripts/nas-write-probe.sh: for each configured share it checks for a live smbfs mount, checks the directory, writes a small file there, reads it back, compares and deletes it, every step that touches the share under a timeout, retrying once. A run that is stopped removes its file; a directory outside its mount point is refused. It writes nas_write_probe_* metrics for node_exporter's textfile collector. NasWriteProbeFailed (critical, two runs), NasShareNotMounted and NasWriteProbeSilent (warnings) follow.
  • Studio enables it with the backup share's Backups directory.
  • modules/services/AGENTS.md and the README describe it. One assertion in test_fseventsd_watchdog.py assumed the watchdog was the only textfile/rule contributor on Studio; it now checks only that none of the watchdog's remain.

Checks

  • python3 scripts/test_nas_storage_health.py (31): the probe against stand-in mounts (writable, read-only, unmounted, non-SMB, missing directory, a hanging write, a hanging directory check, a failed write that left a file, a stopped run, stale read-back, a blip that passes on retry, two shares; the metrics file replaced whole); Studio's agent and node_exporter wiring; a host without monitoring; the refusals; promtool check rules; promtool test rules on series in the shape the NAS's exporter records, where a mirrored pool's devices drop off and the read-only flag stays 0. Mutations fail the tests: a raised threshold, a short window, the rule rewritten onto the read-only metric, removing the up and mounted guards, the read-back comparison, the retry, the cleanup paths, the timed directory check, the atomic metrics write, the mount-point check and the grouped summary.
  • The rule's expression, run against this Prometheus's own history, fires at each recorded fault and is quiet now.
  • One real probe run against the mounted share: success, nothing left behind.
  • All scripts/test_*.py pass; darwin-rebuild build --flake .#studio builds.

Review

An independent read-only Pi reviewer approved with two should-fixes (an untimed directory check on the share; an untested cleanup path) and seven nits; all fixed with tests, re-review approved, and its two follow-up nits (stop timeout, tests for the rule tweaks) fixed with tests.

Live after the next update-system.

Part of #10 (piece N10.5): alert rules for NAS storage health. ## What changes A new module, `services.nas-storage-health`, alerts on NAS storage faults from two signals. Neither relies on the filesystem's read-only flag, which can lag a failed pool. - **btrfs error counters.** The NAS's node_exporter (the existing `unraid-node` job) exports per-device btrfs error counters. `NasBtrfsDeviceErrors` (critical) fires on any increase over 30 minutes, per device and error type; counts that are already there never fire. `NasBtrfsMetricsMissing` (warning) covers the collector failing, or a filesystem seen in the last day vanishing while the exporter is up. - **A write probe.** A user LaunchAgent (`org.nixos.nas-write-probe`, every 10 minutes) runs `scripts/nas-write-probe.sh`: for each configured share it checks for a live smbfs mount, checks the directory, writes a small file there, reads it back, compares and deletes it, every step that touches the share under a timeout, retrying once. A run that is stopped removes its file; a directory outside its mount point is refused. It writes `nas_write_probe_*` metrics for node_exporter's textfile collector. `NasWriteProbeFailed` (critical, two runs), `NasShareNotMounted` and `NasWriteProbeSilent` (warnings) follow. - Studio enables it with the backup share's `Backups` directory. - `modules/services/AGENTS.md` and the README describe it. One assertion in `test_fseventsd_watchdog.py` assumed the watchdog was the only textfile/rule contributor on Studio; it now checks only that none of the watchdog's remain. ## Checks - `python3 scripts/test_nas_storage_health.py` (31): the probe against stand-in mounts (writable, read-only, unmounted, non-SMB, missing directory, a hanging write, a hanging directory check, a failed write that left a file, a stopped run, stale read-back, a blip that passes on retry, two shares; the metrics file replaced whole); Studio's agent and node_exporter wiring; a host without monitoring; the refusals; `promtool check rules`; `promtool test rules` on series in the shape the NAS's exporter records, where a mirrored pool's devices drop off and the read-only flag stays 0. Mutations fail the tests: a raised threshold, a short window, the rule rewritten onto the read-only metric, removing the `up` and `mounted` guards, the read-back comparison, the retry, the cleanup paths, the timed directory check, the atomic metrics write, the mount-point check and the grouped summary. - The rule's expression, run against this Prometheus's own history, fires at each recorded fault and is quiet now. - One real probe run against the mounted share: success, nothing left behind. - All `scripts/test_*.py` pass; `darwin-rebuild build --flake .#studio` builds. ## Review An independent read-only Pi reviewer approved with two should-fixes (an untimed directory check on the share; an untested cleanup path) and seven nits; all fixed with tests, re-review approved, and its two follow-up nits (stop timeout, tests for the rule tweaks) fixed with tests. Live after the next `update-system`.
Alert on NAS storage faults from two signals: new btrfs device errors in
the NAS's node_exporter (unraid-node job), and a write probe that writes,
reads back and removes a small file on the backup share every 10 minutes.
Neither relies on the filesystem's read-only flag.

New module services.nas-storage-health with rules NasBtrfsDeviceErrors,
NasBtrfsMetricsMissing, NasWriteProbeFailed, NasShareNotMounted and
NasWriteProbeSilent; enabled on Studio. Tested with
scripts/test_nas_storage_health.py, including promtool test rules on
recorded-shape series.
Check the probe directory under the timeout, so a stalled share fails the
probe instead of blocking it; remove the probe file and the temporary
metrics file when a run is stopped; refuse a directory outside its mount
point. A device-independent summary for NasBtrfsDeviceErrors, and match
vanished filesystems on instance and uuid. Tests for each.
ExitTimeOut outlasts one timed step, so a stopped probe cleans up before
launchd's SIGKILL. Tests for the device-independent summary and for a
relabelled filesystem not counting as missing.
bryan manually merged commit ae5cfaa06b into main 2026-11-10 17:30:26 +00:00
Sign in to join this conversation.
No reviewers
No labels
ready-for-agent
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bryan/nix-configs!14
No description provided.