feat(host_agent): NFS delay per mount, read from /proc/self/mountstats (#5996)
CI / lint (push) Successful in 2s
CI / unit (push) Failing after 1m32s
CI / integration (push) Successful in 1m31s
CI / publish (push) Skipped

Each sample carries each NFS mount's requests since the last one: how many
a second, their round trip and execute time (READ and WRITE on their own),
and how many were sent again or hit a major timeout. mountstats is the
kernel's own count and never touches the share, so it reads while one is
stuck. Steward stores them per mount and the slowest on the host as
nfs_exe_max_ms, for an "NFS slow" rule and the host page's NFS chart beside
mounts_stalled; each mount's bar says what a request took.

Agent 1.22.0 (which also carries the backlog order from 41fc807).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-17 09:46:14 -04:00
co-authored by Claude Opus 5.5
parent 2df8431de9
commit 3f9aae7f46
12 changed files with 282 additions and 13 deletions
@@ -151,3 +151,52 @@ def test_a_mount_that_errors_is_left_out_not_the_whole_list():
patch.object(a.os, "statvfs", side_effect=OSError):
out = a.collect_storage(["/", "/nfs/gone"])
assert out == [{"mount": "/", "total_bytes": 10, "used_bytes": 1}]
# ─── NFS delay per mount (#5996) ─────────────────────────────────────────────
MOUNTSTATS = (
"device proc mounted on /proc with fstype proc\n"
"device 192.168.0.7:/volume1/data mounted on /nfs/data with fstype nfs4 statvers=1.1\n"
"\topts:\trw,vers=4.1,hard,proto=tcp\n"
"\tper-op statistics\n"
"\t NULL: 0 0 0 0 0 0 0 0 0\n"
"\t READ: 10 10 0 1200 40960 5 30 40 0\n"
"\t WRITE: 4 4 0 8192 512 2 20 24 0\n"
"\n"
"device 192.168.0.5:/volume1/My Media mounted on /nfs/my\\040media with fstype nfs statvers=1.1\n"
"\tper-op statistics\n"
"\t GETATTR: 3 3 0 300 300 0 3 3 0\n"
"device /dev/sda1 mounted on / with fstype ext4\n"
)
def test_mountstats_reads_each_nfs_mount_s_ops_and_skips_the_rest():
got = a.read_mountstats(MOUNTSTATS)
assert set(got) == {"/nfs/data", "/nfs/my media"}
assert got["/nfs/data"]["READ"] == (10, 10, 0, 5, 30, 40)
assert got["/nfs/data"]["NULL"] == (0, 0, 0, 0, 0, 0)
assert got["/nfs/my media"] == {"GETATTR": (3, 3, 0, 0, 3, 3)}
def test_mountstats_that_cannot_be_read_is_no_mounts(tmp_path):
with patch.object(a, "MOUNTSTATS_PATH", str(tmp_path / "missing")):
assert a.collect_nfs_raw() == {}
def test_nfs_delay_is_what_the_requests_since_the_last_sample_took():
prev = {"/nfs/data": {"READ": (10, 10, 0, 5, 30, 40), "WRITE": (4, 4, 0, 2, 20, 24)},
"/nfs/idle": {"GETATTR": (3, 3, 0, 0, 3, 3)},
"/nfs/remounted": {"READ": (50, 50, 0, 0, 50, 50)}}
cur = {"/nfs/data": {"READ": (20, 21, 1, 7, 130, 240), "WRITE": (4, 4, 0, 2, 20, 24)},
"/nfs/idle": {"GETATTR": (3, 3, 0, 0, 3, 3)},
"/nfs/remounted": {"READ": (2, 2, 0, 0, 2, 2)},
"/nfs/new": {"READ": (5, 5, 0, 0, 5, 5)}}
got = {r["mount"]: r for r in a.nfs_delays(cur, prev, 10.0)}
# ten READs in 10 s, 100 ms of round trip and 200 ms of waiting between
# them, one sent twice and one that hit a major timeout; no WRITE finished
assert got["/nfs/data"] == {"mount": "/nfs/data", "ops_per_sec": 1.0, "retrans": 1, "timeouts": 1,
"rtt_ms": 10.0, "exe_ms": 20.0, "read_ms": 20.0}
assert got["/nfs/idle"] == {"mount": "/nfs/idle", "ops_per_sec": 0.0, "retrans": 0, "timeouts": 0}
assert set(got) == {"/nfs/data", "/nfs/idle"} # counters gone back, or no baseline yet
assert a.nfs_delays(cur, prev, 0) == []