Skip to content
felipefrizzoPublic

About

Single-binary system monitor for small Linux hosts (Raspberry Pi)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

pistat

A single-binary system monitor for small Linux hosts, built for a Raspberry Pi running Pi-hole.

  • One binary, no dependencies. Collectors, ring buffer, HTTP server and UI are all in one static executable. No agent, no database, no runtime.
  • Nothing is written to disk. Samples live in memory. A monitoring daemon that writes a time series to an SD card is a monitoring daemon that eventually destroys the machine it monitors.
  • No privileges. Everything is read from /proc and /sys as an unprivileged user, so the shipped systemd unit can be locked down hard.
  • No Node. The UI is Preact and uPlot bundled by esbuild's Go API, so go build is the only toolchain a contributor needs.

Status

Collectors for CPU, memory, thermal, throttle, clock, disk, filesystem, network, uptime and self-monitor are in tree, with a Prometheus /metrics endpoint and a process top list. Packaging and release automation land via GoReleaser. Every green push to main runs svu against conventional commits (feat → minor, fix → patch, ! / BREAKING CHANGE → major under v0 rules) and, when the version changes, tags and releases.

Install

From a release (recommended)

curl -fsSL https://raw.githubusercontent.com/felipefrizzo/pistat/main/scripts/install.sh | sudo bash

Or download a binary from the releases page, or build from source:

git clone https://github.com/felipefrizzo/pistat
cd pistat
make build

Then install it as a service:

sudo install -m 0755 bin/pistat /usr/local/bin/pistat
sudo install -m 0644 packaging/pistat.service /etc/systemd/system/
sudo systemctl enable --now pistat

On first start pistat generates an access token, writes it to /etc/pistat/config.toml with owner-only permissions, and logs it once:

journalctl -u pistat | grep 'generated a new access token'

Open http://<host>:9700 and paste the token in.

Configuration

Settings resolve in this order, each overriding the one after it: command-line flag, environment variable, configuration file, built-in default.

Flag Environment File key Default
-listen PISTAT_LISTEN listen :9700
-tls-cert PISTAT_TLS_CERT tls_cert none
-tls-key PISTAT_TLS_KEY tls_key none
PISTAT_TOKEN token generated
-config /etc/pistat/config.toml when writable, else ~/.config/pistat/config.toml
-interval 1s
-root /
listen = ":9700"
token = "..."

[collectors]
thermal = false

Security

pistat serves plain HTTP by default, which means the session cookie crosses your network in the clear. On a home LAN that is usually an accepted risk; if it is not, set tls_cert and tls_key, or put pistat behind a proxy that terminates TLS. The cookie only carries the Secure attribute when pistat itself is serving HTTPS.

The API is read-only. There is no endpoint that kills a process, restarts a service or reboots the host, which keeps the attack surface of a daemon running next to your DNS server as close to zero as a network service gets.

HTTP API

Endpoint Purpose
POST /api/login Exchange the token for a session cookie
POST /api/logout Invalidate the session
GET /api/session Whether the caller is authenticated
GET /api/history?tier=live|history Backfill, as columnar JSON
GET /api/stream Live samples, as Server-Sent Events
GET /api/processes Top processes by CPU and RSS
GET /metrics Prometheus text exposition

Everything except login and the static bundle requires either the session cookie or Authorization: Bearer <token>.

/api/history is columnar rather than an array of objects, which is both about five times smaller and the exact shape the chart library consumes:

{
  "tier": "live",
  "step_ms": 1000,
  "t": [1785878371026, 1785878372026],
  "series": [
    { "key": "cpu.total", "label": "CPU", "unit": "percent", "v": [3.2, null] }
  ]
}

A reading is null when the collector could not produce it for that sample.

Retention

Two tiers, both in memory, both lost on restart:

Tier Resolution Window
live 1s 5 minutes
history 10s average 6 hours

For anything longer, point Prometheus at pistat rather than making pistat into a database.

Development

make ui            # bundle the front-end into web/dist
make build         # build for the host
make check         # gofmt, go vet, go test
make run-fixture   # run against captured fixtures, for UI work off-target
make help          # everything else

web/dist is a committed build artefact so that go build alone produces a working binary. Re-run make ui after changing anything under web/src.

Collectors are tested without a Raspberry Pi

Every collector reads through an fs.FS rooted at /, so the entire set can be pointed at a directory of captured kernel files and tested on any platform. scripts/capture-fixtures.sh produces such a capture from a real host, including a second sample one second later so that counter-delta logic is exercised against real numbers rather than invented ones.

scp scripts/capture-fixtures.sh pi@raspberrypi:~/
ssh pi@raspberrypi './capture-fixtures.sh'

The script reads only, needs no privileges, and skips process command lines and MAC addresses. Review a capture before committing anything from it: it contains the host's process list and mount layout.

Front-end dependencies

Preact and uPlot are committed under web/vendor rather than installed, because esbuild bundles but does not resolve packages from a registry, and requiring npm would put Node back in the build. scripts/vendor-web-deps.sh re-fetches them from the npm registry and verifies the published SHA-512 integrity hash. See web/vendor/README.md for versions and licences.

Roadmap

Shipped:

  • CPU total and per-core, memory and swap, SoC temperature
  • Throttle/undervoltage latch, CPU clock, disk I/O, filesystem capacity, network rates, uptime, self-monitor
  • Top processes via /api/processes
  • Two-tier in-memory retention, SSE streaming, columnar backfill
  • Token authentication with session cookies, optional TLS
  • Prometheus /metrics
  • Hardened systemd unit, GoReleaser, install script, CI

Possible later:

  • Optional Pi-hole collector
  • Remote sink / fleet mode
  • Curated fixtures from more board models

Licence

Apache 2.0. See LICENSE.

About

Single-binary system monitor for small Linux hosts (Raspberry Pi)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages