code wiki / _hdl_build / nx_resmon.nx

nx_resmon.nx

buildroot/runtime/_hdl_build/nx_resmon.nx

49276 B789 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_resmon_lib.nx nx_proc_ctl.nx nx_logtail.nx nx_resmon.nx

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

main rm_streq rm_trend rm_conf rm_field rm_slen rm_trend_read_tail lt_read_tail sys_openat_rd sys_lseek sys_close sys_read lt_shift_down rm_puts sys_write rm_slen ↻ rm_num nxi_out nxi_fd sys_mmap nxa_die nxa_lock_take nxa_lock_give nxa_report_overrun ccz_cat_num nxi_buf sys_write ↻ sys_munmap rm_line_word rm_slen ↻ rm_line_num rm_slen ↻ rm_streq ↻ rm_trend_log rm_puts ↻ rm_num ↻ rm_lnum sys_mmap ↻ sys_munmap ↻ rm_lcat

structs

none

consts

25const RM_MAGIC_1941: i64 = 1941
26const RM_MAGIC_1024: i64 = 1024
27const RM_MAGIC_262144: i64 = 262144
29const RM_DIRBUF: i64 = 65536
31const RM_DISK_AMBER_DEFAULT: i64 = 5368709120
32const RM_DISK_RED_DEFAULT: i64 = 1073741824
37const RM_DISK_PATH_ESTATE: *u8 = "."
38const RM_DISK_PATH_ROOT: *u8 = "/"
43const RM_DISK_AMBER_ROOT_DEFAULT: i64 = 536870912
44const RM_DISK_RED_ROOT_DEFAULT: i64 = 268435456
54const RM_TREND_LOG: *u8 = "knowledge/status/resmon_trend.log"
55const RM_TREND_MAX_AGE_DEFAULT: i64 = 9000
56const RM_TRENDLOG: *u8 = "knowledge/status/resmon_trend.log"
101const RM_STATBUF: i64 = 4096
130const RM_LOADAVG: *u8 = "/proc/loadavg"
131const RM_LOADAVG_CAP: i64 = 128
132const RM_ASCII_ZERO: i64 = 48 // '0' -- decimal-digit floor for the loadavg parser
133const RM_ASCII_NINE: i64 = 57 // '9' -- decimal-digit ceiling
134const RM_ASCII_DOT: i64 = 46 // '.' -- the loadavg decimal point, skipped so 14.49 -> 1449
232const RM_TREND_NAMEW: i64 = 64
237const RM_TREND_MAXLINES: i64 = 8192
238const RM_LOGCAP: i64 = 1048576

functions

67func rm_trend_log(nm: *u8, newest: i64, grew: i64, span: i64, shrank: i64, flat: i64, delta: i64, observed: i64, v: *u8) -> i64
135func rm_load1_centi() -> i64
called by 1: rm_log
163func 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
called by 1: main calls 3: rm_lcatrm_lnumrm_load1_centi
243func rm_line_num(buf: *u8, lo: i64, hi: i64, key: *u8) -> i64
called by 1: rm_trend calls 1: rm_slen
274func rm_line_word(buf: *u8, lo: i64, hi: i64, key: *u8, out: *u8, cap: i64) -> i64
called by 1: rm_trend calls 1: rm_slen
303func rm_streq(a: *u8, b: *u8) -> i64
called by 2: rm_trendmain
312func rm_tg_find(b: *u8, s: i64, e: i64, pat: *u8) -> i64
called by 1: rm_trend_gatereg
330func rm_trend_gatereg(maxage: i64, namebuf: *u8) -> i64
called by 1: main calls 1: rm_tg_find
370func rm_trend(logpath: *u8) -> i64
486func main(argc: i64, argv: *i64) -> i64