code wiki / (root) / nx_sweep_daemon_lib.nx

nx_sweep_daemon_lib.nx

buildroot/runtime/nx_sweep_daemon_lib.nx

20675 B423 linesdepth 3pulls 5 transitivereach 2 importersview sourcekind librarytopic sweep
docsdependenciesstructsconstsfunctions

about

nx_sweep_daemon_lib.nx -- STANDING SWEEP, library half: parse the data-driven check registry, run every check under its deadline (via nx_sweep_core -- timeout-kill so the sweep never hangs), hold results in memory, and render a PLAIN-ENGLISH status page (per the dashboards-speak-plain-English doctrine: questions + YES/NOT-YET/TIMED-OUT chips, never ledger keys). Data-driven: a check = one registry row, never code. Callable by the gate (run_all in-process) and the daemon (serve loop). license_tier: ORIGINAL

dependencies 3 imports · 2 importers

nx_sweep_core.nx nx_vsz_watchdog_core.nx nx_metrics_ring.nx nx_sweep_daemon_lib.nx nx_sweep_daemon.nx nx_sweep_daemon_gate.nx

imports: nx_sweep_core.nxnx_vsz_watchdog_core.nxnx_metrics_ring.nx

imported by: nx_sweep_daemon.nxnx_sweep_daemon_gate.nx

structs

none

consts

10const SD_MAX_CHECKS: i64 = 64 // registry capacity
11const SD_REG_CAP: i64 = 131072 // registry file read cap
12const SD_LINE_CAP: i64 = 4096 // one row
13const SD_FIELD_CAP: i64 = 2048 // one field
14const SD_ARGV_MAX: i64 = 24 // argv slots per check (matches the compiler's arg cap)
15const SD_OUT_CAP: i64 = 65536 // captured stdout per check
16const SD_PIPE: i64 = 124 // '|'
17const SD_NL: i64 = 10 // '\n'
18const SD_HASH: i64 = 35 // '#'
19const SD_SPACE: i64 = 32 // ' '
20const SD_TAB: i64 = 9 // '\t'
21const SD_ASCII_0: i64 = 48 // '0'
22const SD_ASCII_9: i64 = 57 // '9'
23const SD_DEC: i64 = 10
25const SD_COL_NAME: i64 = 0
26const SD_COL_Q: i64 = 1
27const SD_COL_CWD: i64 = 2
28const SD_COL_ARGV: i64 = 3
29const SD_COL_TMO: i64 = 4
30const SD_COL_EXPECT: i64 = 5
34const SC_N: i64 = 0 // check count
35const SC_NAME: i64 = 1 // -> name string ptrs
36const SC_Q: i64 = 2 // -> question string ptrs
37const SC_CWD: i64 = 3 // -> cwd string ptrs
38const SC_ARGV: i64 = 4 // -> argv vector ptrs
39const SC_TMO: i64 = 5 // deadline ms
40const SC_EXPECT: i64 = 6 // expected exit
41const SC_VERDICT: i64 = 7 // last verdict
42const SC_EXIT: i64 = 8 // last raw exit/sentinel
43const SC_MS: i64 = 9 // last duration ms
44const SC_RED: i64 = 10 // consecutive non-PASS (alert dedup)
45const SC_HASH: i64 = 11 // -> per-check FNV-1a name hash (the metrics-ring key)
46const SC_UPTIME: i64 = 12 // -> per-check uptime permille over the window (-1 = no history)
47const SC_ACC_UP: i64 = 13 // -> scratch: per-check "up" sample count this refresh
48const SC_ACC_TOT: i64 = 14 // -> scratch: per-check total sample count this refresh
49const SC_ARRAYS: i64 = 15 // slots 0..14 = count + 14 per-check arrays (the sd_new loop bound)
52const SC_OUT: i64 = 15 // -> capture buffer (SD_OUT_CAP)
53const SC_OLEN: i64 = 16 // -> outlen cell (one i64)
54const SC_OP: i64 = 17 // -> render/http offset cell (one i64)
55const SC_CORE: i64 = 18 // -> core scratch for sw_run_deadline (fds/pf/stp)
56const SC_STAT: i64 = 19 // -> statbuf/ring-read scratch (SD_STATBUF bytes: mtime probe + ring hdr/rec)
57const SC_MTIME: i64 = 20 // VALUE slot: registry mtime at last successful load (hot-reload gate)
58const SC_TOTAL: i64 = 21 // ctx cell count
59const SD_STATBUF: i64 = 256 // struct stat scratch (also holds ring hdr 64 + rec 32)
60const SD_STAT_MT: i64 = 11 // st_mtim.tv_sec = i64[11] of struct stat (the ccz_mtime idiom)
61const SC_WORD: i64 = 8 // bytes per i64
62const SD_PTR1: i64 = 8 // single-i64 scratch cell
63const SD_CORE_SCR: i64 = 64 // sw_run_deadline scratch: fds(16)+pf(8)+stp(16), rounded up
64const SD_UPWINDOW_S: i64 = 86400 // uptime window = 24h (a threshold -> named, rule 11)
65const SD_PERMILLE: i64 = 1000 // permille scale
66const SD_NODATA: i64 = 0 - 1 // uptime sentinel: no samples in window
68const MR_H_WIDX: i64 = 24 // header: write index
69const MR_H_WRAP: i64 = 32 // header: wrapped flag
70const MR_R_HASH: i64 = 8 // record: name-hash field
71const MR_R_VERD: i64 = 16 // record: verdict field
72const MR_WRAPPED: i64 = 1 // wrapped-flag value

functions

74func sd_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: gg_idx
76func sc_arr(ctx: *i64, k: i64) -> *i64 { return ctx[k] as *i64 }
77func sc_n(ctx: *i64) -> i64 { return ctx[SC_N] }
called by 2: gg_idxmain
80func sd_new() -> *i64
called by 2: mainmain
102func sd_mtime(ctx: *i64, path: *u8) -> i64
110func sd_now_sec(ctx: *i64) -> i64
called by 1: main calls 1: sys_clock_gettime_real
116func sd_reload_if_changed(ctx: *i64, reg_path: *u8) -> i64
called by 2: mainmain calls 2: sd_mtimesd_load
125func sd_ws(c: i64) -> i64 { if c == SD_SPACE { return 1 } if c == SD_TAB { return 1 } return 0 }
called by 1: sd_field
127func sd_field(line: *u8, ll: i64, k: i64) -> *u8
called by 1: sd_load calls 1: sd_ws
164func sd_atoi(s: *u8) -> i64
called by 1: sd_load
177func sd_build_argv(argstr: *u8) -> *i64
called by 1: sd_load
196func sd_load(ctx: *i64, reg_path: *u8) -> i64
244func sd_run_all(ctx: *i64) -> i64
279func sd_ring_scan(ctx: *i64, ring: *u8, now: i64, window: i64) -> i64
called by 1: sd_sample calls 3: sc_arrmr_preadmr_geti
320func sd_sample(ctx: *i64, ring: *u8, now: i64, window: i64) -> i64
346func sd_app(buf: *u8, op: *i64, cap: i64, src: *u8) -> i64
357func sd_appn(buf: *u8, op: *i64, cap: i64, v: i64) -> i64
380func sd_render_status(ctx: *i64, buf: *u8, cap: i64) -> i64
called by 2: mainmain calls 3: sc_arrsd_appsd_appn