# 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."; } ]; }; }