GET /health only gave a snapshot, so the monitoring missed the 2026-11-03
saturation and the nights before it. A one-minute tick, armed in the
require.main block, now records host load, CPU by /proc/stat difference
and, when TLS_PROBE_HOSTS is set, the TLS handshake time of each listed
host into an in-memory buffer of 1440 samples (load-history.js, pure).
- /health gains `saturation` ({state: ok|saturated|unknown, since,
coverageMinutes, load1, cores}) and `tls`, appended after the existing
keys. Saturated = the last five samples of an unbroken series all have
load1 > cores; unknown under five samples, after a gap over 3 minutes,
or when the last sample is over 3 minutes old. No sample at start-up,
so the state stays unknown for the first five minutes after a deploy.
- GET /health/history (read token) serves {since, coverageMinutes, cores,
samples}. The buffer restarts from zero at every deploy.
- probeTls() verifies the certificate, times out after 3 s and reports an
error code only. TLS_PROBE_HOSTS is empty by default: no network call in
the tests, the CI or boot-from-copy.sh.
- Dockerfile COPY, REVIEW.md Haut table (and review-levels.py), CLAUDE.md,
docs and .env.example updated.
Refs #73
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3.3 KiB
vps-health-api
Lightweight health monitoring API for the VPS. Node 22, HTTP-native, zero runtime deps.
Endpoints
Read endpoints require Authorization: Bearer $HEALTH_TOKEN. Each write
endpoint has its own token — $HOSTS_INGEST_TOKEN for workstation snapshots,
$CLAUDE_USAGE_INGEST_TOKEN for the Claude usage snapshot,
$BACKUPS_INGEST_TOKEN for the backup pull report — so an agent can push its
data without gaining read access to the Defenseurs reports, and no ingestion
token opens another one's route.
| Method | Path | Token | Description |
|---|---|---|---|
| GET | /health |
HEALTH_TOKEN |
CPU, memory, disk, uptime, Logto reachability, load saturation, TLS handshake times |
| GET | /health/history |
HEALTH_TOKEN |
Up to 24 h of one-minute load samples (in memory, reset at every deploy) |
| GET | /defenseurs |
HEALTH_TOKEN |
Defenseurs executive status (status.json) |
| GET | /defenseurs/findings?project=X |
HEALTH_TOKEN |
Detailed findings for a project's Defenseur |
| GET | /defenseurs/state |
HEALTH_TOKEN |
Sergent's per-finding state (findings-state.json) |
| GET | /reports/scans?date=YYYY-MM-DD |
HEALTH_TOKEN |
Aggregated scan reports for a UTC date |
| GET | /hosts |
HEALTH_TOKEN |
Latest snapshot of every allowlisted workstation |
| POST | /hosts/<id> |
HOSTS_INGEST_TOKEN |
Ingest one workstation snapshot |
| GET | /claude-usage |
HEALTH_TOKEN |
Latest Claude usage snapshot, with server-side staleness |
| POST | /claude-usage |
CLAUDE_USAGE_INGEST_TOKEN |
Ingest the Claude usage snapshot |
| GET | /claude-usage/history?from=YYYY-MM&to=YYYY-MM |
HEALTH_TOKEN |
Archived closed days of Claude usage (12 months by default) |
| GET | /backups |
HEALTH_TOKEN |
PostgreSQL backups: VPS status and last workstation pull, with server-side staleness |
| POST | /backups/pull |
BACKUPS_INGEST_TOKEN |
Ingest the workstation's pull report |
Routing resolves before authentication: an unknown path or a wrong method
answers 404, never 401.
Full contract of every route — bodies, response codes, examples, the
whitelist rebuild and the atomic writes behind the three POST routes:
docs/endpoints.md (in French).
Config
Environment variables and their defaults are listed in
CLAUDE.md (« Config »). Every token is fail-closed: a missing
HEALTH_TOKEN answers 401 on reads, a missing ingest token 503 on its own
route.
Bind-mounts (Coolify)
Three read-only mounts (the Defenseurs files and the VPS backup status) and
three read-write ones owned by uid 1000 (/data/hosts, /data/claude-usage,
/data/backups-pull), always mounting the directory, never the file. Paths,
the two layers that keep the API out of the Defenseurs files, and the
post-redeploy check: docs/mounts.md (in French).
Workstation agent
agent/ holds the zero-dependency collector that runs from cron on a
workstation and feeds POST /hosts/<id>. It is not part of the server image —
it is installed by copying files onto the machine it measures. Install steps,
crontab line and failure modes: agent/README.md.
Tests
npm install
npm test
bash test-curl.sh
sh scripts/boot-from-copy.sh
What each test file and script guards: docs/tests.md (in French).