. "$BST_LIB" # libstatgrab on wasm32-hwjs glibc: reads system statistics (CPU, memory, # load, network, disk) via /proc/stat, /proc/meminfo, /proc/net/dev, # /proc/mounts, /proc/loadavg -- all present on this machine. # # statgrab outputs key=value lines with dot-separated group.field names, # e.g. cpu.user, mem.total, load.min1, general.hostname. # Without an interval argument it takes one sample and exits. # # saidar is the ncurses companion; it is installed and its binary is # executable but cannot be driven non-interactively, so its presence is # all that is asserted. require statgrab libstatgrab/present # has -- assert a captured sample contains a literal. has() { case "$3" in *"$2"*) bst_ok "$1" ;; *) bst_notok "$1" "no '$2' in capture" ;; esac } # --- identity and inventory -------------------------------------------------- # statgrab has no --version flag; the version appears in the pkg-config file. _ver=$(pkg-config --modversion libstatgrab 2>/dev/null) if [ "$_ver" = "0.92.1" ]; then bst_ok libstatgrab/version else bst_notok libstatgrab/version "pkg-config modversion='$_ver' want='0.92.1'"; fi [ -x /usr/bin/statgrab ] && bst_ok libstatgrab/statgrab-present \ || bst_notok libstatgrab/statgrab-present "/usr/bin/statgrab not executable" [ -x /usr/bin/saidar ] && bst_ok libstatgrab/saidar-present \ || bst_notok libstatgrab/saidar-present "/usr/bin/saidar not executable" # Library file: shared (.so*) on glibc targets; wasm32 links statically so # only libstatgrab.a ships -- accept either. _lib=$(find /usr/lib -name "libstatgrab.so*" -o -name "libstatgrab.a" 2>/dev/null | head -1) if [ -n "$_lib" ]; then bst_ok libstatgrab/library else bst_notok libstatgrab/library "no libstatgrab.so* or libstatgrab.a under /usr/lib"; fi # --- one-shot sample --------------------------------------------------------- # Capture the full stat dump once; assert each category's key-value block. _sg=$(statgrab 2>&1) _rc=$? if [ "$_rc" -eq 0 ]; then bst_ok libstatgrab/run else bst_notok libstatgrab/run "statgrab exited $_rc"; fi # CPU stats: user/kernel/idle counters (sourced from /proc/stat). # Key format: cpu. has libstatgrab/cpu-user "cpu.user" "$_sg" has libstatgrab/cpu-kernel "cpu.kernel" "$_sg" has libstatgrab/cpu-idle "cpu.idle" "$_sg" # Memory stats (sourced from /proc/meminfo). # Key format: mem. has libstatgrab/mem-total "mem.total" "$_sg" has libstatgrab/mem-free "mem.free" "$_sg" # Load averages (sourced from /proc/loadavg). # Key format: load. has libstatgrab/load "load.min1" "$_sg" # Network stats for the loopback interface (sourced from /proc/net/dev). # Key format: net.. -- lo is always present. has libstatgrab/net "net.lo." "$_sg" # Host info: uptime and hostname live under the "general" group. has libstatgrab/host-uptime "general.uptime" "$_sg" has libstatgrab/host-hostname "general.hostname" "$_sg" # Selective invocation: only memory and load groups. # Group selectors require a trailing dot (they prefix-match against "mem.", "load.", etc.). _ml=$(statgrab mem. load. 2>&1) has libstatgrab/selective-mem "mem.total" "$_ml" has libstatgrab/selective-load "load.min1" "$_ml" # CPU keys must not appear when only mem and load are requested. case "$_ml" in *"cpu.user"*) bst_notok libstatgrab/selective-cpu-absent "cpu.user present in mem+load output" ;; *) bst_ok libstatgrab/selective-cpu-absent ;; esac