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>
34 lines
1.0 KiB
Nix
34 lines
1.0 KiB
Nix
# Metrics for Prometheus. The router's own state is /metrics of the web UI
|
|
# (pkgs/router-webui/promtext.go); the machine's is node_exporter, which this
|
|
# module starts when `router.metrics.nodeExporter.enable` is set and opens to
|
|
# the zones named there, and to no one else.
|
|
{ config, lib, ... }:
|
|
let
|
|
cfg = config.router;
|
|
m = cfg.metrics.nodeExporter;
|
|
in
|
|
{
|
|
config = lib.mkIf (cfg.enable && m.enable) {
|
|
services.prometheus.exporters.node = {
|
|
enable = true;
|
|
inherit (m) port;
|
|
enabledCollectors = [ "systemd" ];
|
|
};
|
|
|
|
# An allow rule per zone; the unknown ones are refused by the firewall's own check.
|
|
router.firewall.rules = map (zone: {
|
|
from = zone;
|
|
to = "local";
|
|
protocol = "tcp";
|
|
ports = [ m.port ];
|
|
}) m.zones;
|
|
|
|
assertions = [
|
|
{
|
|
assertion = !(lib.elem "wan" m.zones);
|
|
message = "router.metrics.nodeExporter.zones: `wan` is the internet; node_exporter must not be open to it. Scrape it from a LAN or through a WireGuard tunnel.";
|
|
}
|
|
];
|
|
};
|
|
}
|