Project

bx-monitor-collector

The other half of bx-monitor: a collector and dashboard you run yourself, built on boxlang-express with a React front end. Your BoxLang servers push their registration, heartbeats and errors to it, and one page shows every server: which are up, which have gone quiet, their heap, their request timings and their errors. It makes no outbound requests and reports to nobody.

v0.1.0 ·

One container

One image for amd64 and arm64, one volume, SQLite by default. Point it at a MySQL or MariaDB you already run instead, and it creates its own tables.

Every server on one page

Online, stale, lost or stopped, trouble first. Each server's page charts heap, p95, requests, errors, CPU and threads, shows when each check wasn't ok, and ranks its routes.

Errors, grouped

The same error across servers is one group, with a trend and recent samples. Resolve hides one until it happens again; mute hides it for good.

Never runs open

It won't start without an API key for agents and a login for the dashboard. Expose just /api/v1/* to your servers and keep the dashboard private.

The servers page: one card per server with its state, heap, uptime and errors

Run it

You need Docker. Pick an API key (openssl rand -hex 32 makes one) and a password for the dashboard:

bashdocker run -d --name bx-monitor-collector --restart unless-stopped \
  -p 8080:8080 -v bx-monitor-data:/data \
  -e MONITOR_API_KEYS=<key> -e MONITOR_ADMIN_USER=admin -e MONITOR_ADMIN_PASSWORD=<password> \
  ghcr.io/robertz/bx-monitor-collector:latest

Open http://localhost:8080 and log in. Everything it stores is in the bx-monitor-data volume. latest follows main; pin a version tag (:0.1.0) in production. The repository also has Compose files, for SQLite and for MySQL.

To see it with something in it, run the fake agent, which pretends to be six servers in every state:

bashdocker exec -it bx-monitor-collector boxlang scripts/fake-agent.bxs

Point a server at it

Install bx-monitor on a BoxLang server and give it the collector's address and one of the keys in MONITOR_API_KEYS, in that server's boxlang.json:

json"modules": {
	"bxMonitor": {
		"settings": {
			"collectorUrl": "https://monitor.example.com",
			"apiKey": "${env.BX_MONITOR_KEY}",
			"serverName": "feedhouse-prod"
		}
	}
}

The server registers when it starts and heartbeats at the interval the collector tells it. Everything it sends is in the protocol, which is also all you need to write your own collector or emitter.

Behind a proxy or tunnel

The collector speaks plain HTTP: put TLS in front with a reverse proxy or a Cloudflare Tunnel, and set MONITOR_TRUST_PROXY=1 so the session cookie is Secure and the login rate limit sees each visitor's address. Only /api/v1/* has to be reachable by your servers, and it's protected by the API key. Leave everything else on your private network, or behind Cloudflare Access.

Settings

Environment variables. Required: MONITOR_API_KEYS (comma-separated for more than one), MONITOR_ADMIN_USER and MONITOR_ADMIN_PASSWORD. Optional: MONITOR_DB_DRIVER (sqlite or mysql) and its connection settings, MONITOR_HEARTBEAT_INTERVAL_SEC (30; stale and lost are 2× and 5× this), HEARTBEAT_RETENTION_DAYS (7), ERROR_RETENTION_DAYS (30), MONITOR_ERROR_SAMPLES per group (20), MONITOR_MAX_BODY_BYTES (1 MB), MONITOR_SESSION_DAYS (30) and MONITOR_MAX_LOGIN_ATTEMPTS (10 per 15 minutes). The README lists them all.

Things to know

  • Ten servers at a 30-second interval write about 29,000 heartbeat rows a day. Old rows are pruned at start and every hour after.
  • Wiping the database is safe: each server gets a 409 on its next heartbeat, registers again and reappears.
  • Stop the collector before copying the SQLite files for a backup. Heartbeats sent while it's stopped are lost.
  • Not in v1: alerting, more than one user, websockets (the dashboard polls every 10 seconds), Prometheus export and multi-tenancy.