code wiki / _hdl_build / nx_resmon.nx
nx_resmon.nx
buildroot/runtime/_hdl_build/nx_resmon.nx
about
nx_resmon.nx -- the RESOURCE axis the health plane never had (debt seq897 / seq1005).
WHY THIS EXISTS: on 2026-07-25 nx_health returned {overall:OK, degraded:0, down:0} while the box was
at 93.4% swap exhaustion with nr_vmscan_immediate_reclaim 1.33e9 -- sustained thrash. The health plane
probes GATEWAYS ONLY, so the single most destabilising condition on the platform was invisible to
every instrument we owned.
LAW: an instrument that reports OK during the worst outage class it could ever see is not an instrument.
TWO AXES:
A. PRESSURE -- swap consumed / memory available. A LAGGING indicator: by the time it is red the
box is already thrashing.
B. LEAK CENSUS -- processes whose VmSize == VmPeak above a COMMITTED-memory floor. A LEADING
indicator: it fires while swap is still healthy. This is the fingerprint that
identified the leaking organs in the first place.
This organ owns the /proc walk and the printing ONLY. Both policy predicates live in nx_resmon_lib.nx
so the gate exercises the SAME code this runs (rule 9 single responsibility, rule 15 DRY).
Thresholds are data-driven from knowledge/status/resmon.conf (rule 11). Read-only.
Exit code IS the verdict so a caller can gate on it: 0=GREEN 1=AMBER 2=RED.
license_tier: ORIGINAL expect_exit: 0
dependencies 3 imports · 0 importers
imports: nx_resmon_lib.nxnx_proc_ctl.nxnx_logtail.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 25 | const RM_MAGIC_1941: i64 = 1941 |
| 26 | const RM_MAGIC_1024: i64 = 1024 |
| 27 | const RM_MAGIC_262144: i64 = 262144 |
| 29 | const RM_DIRBUF: i64 = 65536 |
| 31 | const RM_DISK_AMBER_DEFAULT: i64 = 5368709120 |
| 32 | const RM_DISK_RED_DEFAULT: i64 = 1073741824 |
| 37 | const RM_DISK_PATH_ESTATE: *u8 = "." |
| 38 | const RM_DISK_PATH_ROOT: *u8 = "/" |
| 43 | const RM_DISK_AMBER_ROOT_DEFAULT: i64 = 536870912 |
| 44 | const RM_DISK_RED_ROOT_DEFAULT: i64 = 268435456 |
| 54 | const RM_TREND_LOG: *u8 = "knowledge/status/resmon_trend.log" |
| 55 | const RM_TREND_MAX_AGE_DEFAULT: i64 = 9000 |
| 56 | const RM_TRENDLOG: *u8 = "knowledge/status/resmon_trend.log" |
| 101 | const RM_STATBUF: i64 = 4096 |
| 130 | const RM_LOADAVG: *u8 = "/proc/loadavg" |
| 131 | const RM_LOADAVG_CAP: i64 = 128 |
| 132 | const RM_ASCII_ZERO: i64 = 48 // '0' -- decimal-digit floor for the loadavg parser |
| 133 | const RM_ASCII_NINE: i64 = 57 // '9' -- decimal-digit ceiling |
| 134 | const RM_ASCII_DOT: i64 = 46 // '.' -- the loadavg decimal point, skipped so 14.49 -> 1449 |
| 232 | const RM_TREND_NAMEW: i64 = 64 |
| 237 | const RM_TREND_MAXLINES: i64 = 8192 |
| 238 | const RM_LOGCAP: i64 = 1048576 |
functions
| 67 | func rm_trend_log(nm: *u8, newest: i64, grew: i64, span: i64, shrank: i64, flat: i64, delta: i64, observed: i64, v: *u8) -> i64 |
| 135 | func rm_load1_centi() -> i64 called by 1: rm_log |
| 163 | func rm_log(swused_pm: i64, avail_pm: i64, leakers: i64, sustained: i64, leak_observed: i64, worst_kb: i64, worst_nm: *u8, sev: i64, procs_seen: i64, procs_vm: i64) -> i64 |
| 243 | func rm_line_num(buf: *u8, lo: i64, hi: i64, key: *u8) -> i64 |
| 274 | func rm_line_word(buf: *u8, lo: i64, hi: i64, key: *u8, out: *u8, cap: i64) -> i64 |
| 303 | func rm_streq(a: *u8, b: *u8) -> i64 |
| 312 | func rm_tg_find(b: *u8, s: i64, e: i64, pat: *u8) -> i64 called by 1: rm_trend_gatereg |
| 330 | func rm_trend_gatereg(maxage: i64, namebuf: *u8) -> i64 |
| 370 | func rm_trend(logpath: *u8) -> i64 |
| 486 | func main(argc: i64, argv: *i64) -> i64 |