Add Prometheus metrics: /metrics, node_exporter and a page for it

The web UI serves the router's own state at /metrics (token needed);
router.metrics.nodeExporter runs node_exporter for the machine's and opens
its port only to the zones named. The Prometheus page edits those settings
and shows the scrape configuration.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 11:30:02 +01:00
co-authored by Claude Sonnet 5.5
parent 32bf0d5fde
commit 6e23d183fc
13 changed files with 672 additions and 1 deletions
+8
View File
@@ -236,6 +236,14 @@ Upgrading nixpkgs (the kernel and every package) on the router, without a new re
- **Module options** (for tests): `routerSettings.upgrade.channelsUrl`, `routerSettings.upgrade.nixpkgsRef` (`%rev%`).
- **Test** (`apply`): the channel is a small HTTP server on the client that redirects like channels.nixos.org, and the "newer" nixpkgs is the installed one under a `path:` reference with the same `lastModified` and `rev`: a really different nixpkgs cannot be built offline (any version change rebuilds the NixOS tools). Covers check, preview (including the package-list rules), download, an unconfirmed upgrade rolled back with its lock and pin, a confirmed one, and a failing build.
## Metrics for Prometheus (2026-11-19)
Two sources, so nothing the machine already exports is written twice.
- **`/metrics` of the web UI** (`promtext.go`): the router's own state in the text format 0.0.4. A token of the API access page is needed (`Authorization: Bearer`, any scope, so Prometheus' `authorization.credentials` works), and the endpoint is reachable wherever the web UI is (the LANs and tunnels with `allowManagement`); the certificate is the web UI's, so a Prometheus job needs `insecure_skip_verify` or the CA. Metrics: `router_info`, `router_uplink_up`/`_reachable`/`_since_timestamp_seconds`, `router_ping_up`/`_rtt_seconds` (per target), `router_reboot_required{reason}`, `router_settings_unapplied`, `router_apply_running`, `router_confirmation_due_seconds`, `router_dhcp_leases{lan}`, `router_wireguard_peer_last_handshake_timestamp_seconds` and `_receive_bytes_total`/`_transmit_bytes_total` (per tunnel and peer, with the peer's name), `router_certificate_expiry_timestamp_seconds`. A value that is not known (NaN) is left out.
- **node_exporter** (`router.metrics.nodeExporter`, `modules/router/metrics.nix`): CPU, memory, disks, interfaces and systemd units. Off by default. It listens on all addresses, but the firewall opens its port (9100) only to the zones in `zones` (one allow rule each, to `local`); `wan` is refused by an assertion. With no zone it can only be read on the router itself.
- Tested in `webui` (token needed, the samples, node_exporter from the LAN and on the router, the rule names the LAN's device only) and `assertions`. The **Prometheus page** (Services → Prometheus, `exporter.go`) edits the exporter's settings (enable, port, zones to open it to; `wan` and the router's own ports are refused) and shows the scrape config for `/metrics` and for node_exporter. Not done: per-LAN traffic of the web UI's own history (node_exporter has the interface counters), and alert rules or a Grafana dashboard.
## Not done yet (2026-11-01, after 0.12.0)
Remote access