# plugin_nvtop A zero-dependency **C99** local GPU telemetry plugin for SCORPIOX BOT nodes. One binary, three modes, no runtime dependencies, no outbound network requests. It answers the question an operator actually asks about a machine: > **What are the GPUs doing right now, and which processes are using them?** Everything is read from the machine the plugin is installed on. Nothing is sent anywhere. ## What it reports | Mode | Output | |---|---| | `--meta` | `{"name":"nvtop","desc":"Local GPUs"}` — discovery metadata | | `?action=metrics` | Every local GPU: index, UUID, product name, compute utilisation %, VRAM used/total MB, temperature, power draw and power limit; plus every compute process with its GPU UUID, GPU index, PID, name and VRAM | | `?action=info` | Plugin version, platform, PID, auth state, supported actions, the probes it runs and the largest GPU count it will report | | `?format=json` | Alias for `action=metrics` | | `GET` (default) | Responsive dark/light HTML dashboard, `?embed=1` aware | The dashboard renders one card per GPU with an orange **compute %** rolling sparkline and a blue **VRAM** sparkline (60 samples, polled every 2 s), power and thermal chips that turn amber past 70 °C and red past 85 °C, and a compute process table with GPU / PID / process / VRAM. It pauses polling when the tab is hidden. ## Where the numbers come from | Platform | Probe | Notes | |---|---|---| | NVIDIA (any OS) | `nvidia-smi --query-gpu=index,uuid,name,utilization.gpu,memory.used,memory.total,temperature.gpu,power.draw,power.limit,driver_version --format=csv,noheader,nounits` | plus `--query-compute-apps=gpu_uuid,pid,process_name,used_memory` | | AMD (Linux) | `rocm-smi --showproductname --showuse --showmeminfo vram --showtemp --showpower` | VRAM is reported in bytes and converted to MB | | Apple Silicon (macOS) | `ioreg -rc IOAccelerator -d 1` | `Device Utilization %` and `In use system memory` | Every one of those command strings is a **compile-time constant**. Nothing from the query string, and nothing from the environment except the mock path, is ever passed to a shell. `nvidia-smi` prints `N/A` or `[N/A]` for counters a card does not support. Those become JSON `null` and `—` in the UI rather than a zero that looks like data. ## CPU-only nodes On a machine with no local GPU the plugin does not error. It answers: ```json {"ok":true,"available":false,"source":"none","count":0,"gpus":[],"processes":[], "message":"No local NVIDIA/AMD GPU detected"} ``` and the dashboard shows a clean explanatory panel — including how to customize `src/plugin_nvtop.c` if you want to monitor a **remote** GPU rig from this node. That is the honest state for most of a fleet, and it is a first-class UI state, not a failure. ## Deterministic offline testing: `NVTOP_MOCK_CSV` A build box usually has no GPU, so the tests must not depend on one. There are three environment hooks, each gated to a fixture path you provide: ```bash # Invented one-line-per-record format (see the header of tests/fixtures/mock-4gpu.csv) NVTOP_MOCK_CSV=tests/fixtures/mock-4gpu.csv QUERY_STRING='action=metrics' ./plugin_nvtop # Real nvidia-smi csv,noheader layout, with "APP," lines for compute processes NVTOP_MOCK_NVIDIA=tests/fixtures/nvidia-4gpu.csv QUERY_STRING='action=metrics' ./plugin_nvtop # Real rocm-smi "GPU[n] : key: value" text layout NVTOP_MOCK_ROCM=tests/fixtures/rocm-1gpu.txt QUERY_STRING='action=metrics' ./plugin_nvtop ``` The `NVTOP_MOCK_CSV` record format: ``` GPU,,,,,,,,,, APP,,,, ``` `#` lines are comments, and a field of `-` or `N/A` means "this counter is unavailable". Responses served from a fixture carry `"mocked": true` so nobody mistakes test data for a live reading. ## Security properties (verified, not asserted) * **Zero network.** No `socket(`, no `curl`/`wget`, no `ssh`, no `system(` — all asserted against the source text by `tests/run.sh`. * **Auth on every mode except `--meta`.** Accepts `X-Bot-Password`, `Authorization: Bearer `, and `?pwd=`. With `BOT_PASSWORD` unset the check is a deliberate no-op so you can run it from a shell. * **No injection surface.** The only `popen()` calls use fixed command constants; the fixtures are read with `fopen()`. * **No `Content-Length`** — the server owns framing. * **Clean history.** `tests/run.sh` greps `git log -p --all` for LAN IPs, PATs, bare node passwords and fleet paths, and refuses to pass on any hit. ## Build ```bash make # native -> ./plugin_nvtop make musl # fully static musl x86_64 (the universal Linux artifact) make arm64 # static aarch64 (Pi 5 / ARM64 servers) make win64 # static PE via MinGW-w64 -> ./plugin_nvtop.exe make macos # Apple clang (run on macOS) make test # build + tests/run.sh ``` Windows: `powershell -ExecutionPolicy Bypass -File build.ps1`. On Apple Silicon, `make` needs nothing special — the file defines `_DARWIN_C_SOURCE` before any include so ``-style BSD types survive `-std=c99`. ## Install ```bash make && mkdir -p ~/.scorpiox/plugins && cp plugin_nvtop ~/.scorpiox/plugins/ ``` or install from the registry (see below), or let an agent clone, audit, customize and compile it on the node. ## Publish ```bash ./release-dist.sh # secret scan -> multi-target build -> dist upload -> plugingit mirror ./release-dist.sh --dry-run # build and stage in /tmp only ./release-dist.sh --no-macos # skip the macOS legs ``` Artifacts land at `https://dist.scorpiox.net/bot-plugins/nvtop//` with `manifest.json`, `SHA256SUMS`, `source.tar.gz` and a directory per target. `release-dist.sh` **skips** a target it cannot build rather than failing, so always check the target count in `latest.json` — not the exit code. Regions that must be supplied by the environment (never committed): `DIST_HOST`, `DIST_PASS`, `MAC_HOST`, `MAC_USER`, `MAC_PASS`, `PLUGINGIT_TOKEN_FILE`, `PLUGINGIT_REMOTE`. ## Source Public git mirror: `https://plugingit.scorpiox.net/scorpiox-bot-plugin-nvtop.git` ``` src/plugin_nvtop.c single-binary implementation (no headers, no deps) tests/run.sh 130 offline assertions (124 in a bare tree, 130 with the cross builds present) tests/fixtures/ deterministic nvidia / rocm / mock snapshots plugin.json catalog metadata for the Bot Market ``` MIT License. Copyright (c) 2026 SCORPIOX INC. ## Publishing gotchas (learned the hard way) * **The mirror push URL must use the literal user `token`.** `https://token:@plugingit.scorpiox.net/.git` works; `https://@host` and `https://x-access-token:@host` both fail with `could not read Password`. * **`POST /api?r=repos&name=` needs a request body and the header `Authorization: token `.** Without `--data ''` it answers `400`, and with `-u user:pat` it answers `{"ok":false,"error":"Authentication required"}`. * **plugingit's git handler is HTTP/1.1-only in practice.** Over HTTP/2 the push dies with `PROTOCOL_ERROR` before the request is even read — `git -c http.version=HTTP/1.1 push` is the difference between working and not. * **`release-dist.sh` skips what it cannot build.** Always read the target count in `latest.json`, not the exit code.