open-nomad/client/stats
Tim Gross 2d65dc418c
metrics: prevent negative counter from iowait decrease (#18849)
The iowait metric obtained from `/proc/stat` can under some circumstances
decrease. The relevant condition is when an interrupt arrives on a different
core than the one that gets woken up for the IO, and a particular counter in the
kernel for that core gets interrupted. This is documented in the man page for
the `proc(5)` pseudo-filesystem, and considered an unfortunate behavior that
can't be changed for the sake of ABI compatibility.

In Nomad, we get the current "busy" time (everything except for idle) and
compare it to the previous busy time to get the counter incremeent. If the
iowait counter decreases and the idle counter increases more than the increase
in the total busy time, we can get a negative total. This previously caused a
panic in our metrics collection (see #15861) but that is being prevented by
reporting an error message.

Fix the bug by putting a zero floor on the values we return from the host CPU
stats calculator.

Backport-of: #18835
2023-10-24 10:37:46 -04:00
..
cpu.go backport of commit 615e76ef3c23497f768ebd175f0c624d32aeece8 (#17993) 2023-07-19 13:31:14 -05:00
cpu_darwin_test.go backport of commit 615e76ef3c23497f768ebd175f0c624d32aeece8 (#17993) 2023-07-19 13:31:14 -05:00
cpu_test.go backport of commit 615e76ef3c23497f768ebd175f0c624d32aeece8 (#17993) 2023-07-19 13:31:14 -05:00
host.go metrics: prevent negative counter from iowait decrease (#18849) 2023-10-24 10:37:46 -04:00
host_test.go metrics: prevent negative counter from iowait decrease (#18849) 2023-10-24 10:37:46 -04:00