# plugin_sysmon — SCORPIOX BOT open-source local system monitor plugin A clean-room, MIT-licensed [SCORPIOX BOT](https://bot.scorpiox.net) dynamic plugin that shows what **your own node** is doing right now: CPU utilization overall and per core, a rolling history sparkline, RAM and swap, load average, uptime, and the top processes by CPU or memory. One C99 file. No dependencies. No daemon of its own. No outbound network requests. ``` plugin_sysmon --meta {"name":"sysmon","desc":"CPU & memory"} ``` --- ## What it does | Area | Detail | |---|---| | **CPU** | Two counter samples 80 ms apart, so the figure is a live percentage rather than an average since boot. Linux reads `/proc/stat`, macOS reads `host_processor_info`, Windows reads `GetSystemTimes`. | | **Per-core** | One bar per logical core on Linux and macOS. Windows exposes an aggregate figure only, and the UI says so rather than showing a fake bar. | | **History** | The dashboard keeps the last 60 samples in the page and draws them as a polyline SVG. Nothing is cached on disk. | | **Memory** | Total, used, available and cached, plus swap. Linux uses `MemAvailable` (not `MemFree`) so the number matches what `free` reports. | | **Load / uptime** | `/proc/loadavg` + `/proc/uptime` on Linux, `getloadavg` + `kern.boottime` on macOS, `GetTickCount64` on Windows. | | **Processes** | Top 25 by CPU or by RSS, with client-side filter. CPU comes from a per-process tick delta over the same 80 ms window, not from a `ps` column. | | **Polling** | 2 s / 5 s / Pause, default 2 s. Polling stops when the tab is hidden and resumes on focus. | | **Theme** | Follows the Bot theme (`localStorage.bot_theme`), dark by default, no flash. | | **Embed mode** | `?embed=1` drops the back-link so it fits the chat floating window. | ### Why it is safe **1. Node authentication.** The node API on `:8150` is reachable from the LAN, so the plugin refuses any request that does not carry the node password. Accepted forms match the rest of the node API: `X-Bot-Password: ` (what `bot-web` proxies with), `Authorization: Bearer `, or `?pwd=` (what the plugin iframe appends). If `BOT_PASSWORD` is unset the node is running without a password, which is a deliberate local-dev setup only. `--meta` stays unauthenticated so discovery keeps working. **2. No user input reaches a shell.** The only subprocess in the whole program is a fixed `ps -Ao pid=,pcpu=,rss=,comm=` on macOS, where the kernel offers no cheap per-process iterator. Every string it consumes comes from the kernel, not from the request. Query parameters are parsed into fixed-size buffers and are only ever compared to literals. **3. No sockets.** The plugin makes zero outbound connections. It never resolves a hostname, never opens a port, and never reads a credential. **4. `/proc` is streamed, never measured.** `st_size` for `/proc/stat` and `/proc/meminfo` is always 0, so the code reads with `fgets` until EOF. Seeking to the end and asking for the size is a classic bug that silently yields an empty buffer. --- ## Install ### Prebuilt (fastest) ```bash curl -fsSL https://dist.scorpiox.net/bot-plugins/sysmon/latest.json ``` Pick the target that matches the node, then place the binary in the node plugin directory: | Platform | Directory | |---|---| | Linux / macOS | `~/.scorpiox/plugins/`, or `/workspace/.scorpiox/plugins/` in a BotCloud container | | Windows | `%LOCALAPPDATA%\scorpiox\plugins\` | ```bash mkdir -p ~/.scorpiox/plugins chmod +x plugin_sysmon mv plugin_sysmon ~/.scorpiox/plugins/ ~/.scorpiox/plugins/plugin_sysmon --meta ``` No restart is needed — `scorpiox-server` resolves plugin binaries on every request. ### From source (auditable, customizable) ```bash git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-sysmon.git cd scorpiox-bot-plugin-sysmon make # native make musl # fully static Linux x86_64 make win64 # static Windows x64 PE (needs MinGW-w64) make test # 100+ offline assertions against live counters ``` --- ## API All responses are `application/json; charset=utf-8`. No `Content-Length` is ever emitted. ### `GET ?action=metrics` ```json { "ok": true, "action": "metrics", "plugin": "plugin_sysmon", "version": "1.0.0", "platform": "linux", "host": "node-1", "cpu_model": "Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz", "utc": "2026-11-11T04:00:00Z", "cpu_pct": 12.4, "ncores": 6, "cores": [{"core": 0, "pct": 10.0}, {"core": 1, "pct": 18.8}], "mem": {"total_kb": 32710248, "used_kb": 23329068, "free_kb": 9381180, "cached_kb": 7277468, "pct": 71.3}, "swap": {"total_kb": 8388604, "used_kb": 1234, "pct": 0.0}, "uptime_sec": 4077192, "load": {"available": true, "load1": 12.66, "load5": 13.60, "load15": 12.27}, "proc_count": 312, "top": 25, "sort": "cpu", "processes": [ {"pid": 1, "name": "scorpiox", "cpu": 4.5, "rss_kb": 30164, "state": "S"} ] } ``` Parameters: | Param | Values | Default | |---|---|---| | `action` | `metrics`, `info` | `metrics` (when `format=json`) | | `sort` | `cpu`, `mem` | `cpu` | | `top` | 1–4096 | 25 | ### `GET ?action=info` Plugin self-description: version, platform, PID, timestamp, whether node auth is enforced, the sample window, and the supported action list. ### `GET` (no action) Serves the HTML dashboard. `?embed=1` / `?embed=true` drops the back-link. --- ## Build matrix | Target | Compiler | Artifact | |---|---|---| | `linux-x86_64` | `cc` | glibc ELF | | `linux-x86_64-musl` | `musl-gcc -static` | static ELF, universal across distros | | `linux-arm64-musl` | `aarch64-linux-musl-gcc` | static ELF for ARM64 servers | | `macos-arm64` | Apple `clang -arch arm64` | Mach-O | | `macos-x86_64` | Apple `clang -arch x86_64` | Mach-O | | `windows-x86_64` | `x86_64-w64-mingw32-gcc -static` | static PE | `release-dist.sh` builds what the local machine can build, scans the whole git history for secrets and LAN addresses, writes `manifest.json`, `SHA256SUMS` and `source.tar.gz`, uploads to `dist.scorpiox.net/bot-plugins/sysmon//`, refreshes `latest.json` and the registry `index.json`, and mirrors the repo to `plugingit.scorpiox.net`. --- ## Licence MIT. Copyright (c) 2026 SCORPIOX INC.