diff --git a/ops/nixos/default.nix b/ops/nixos/default.nix index 885f1a1468..6e7042b143 100644 --- a/ops/nixos/default.nix +++ b/ops/nixos/default.nix @@ -23,16 +23,24 @@ let systemDrvs = mapAttrs (_: sys: sys.config.system.build.toplevel) evaledSystems; systemTailscaleIPs = lib.mapAttrs' (n: v: lib.nameValuePair v [n]) (lib.filterAttrs (n: v: v != null) (mapAttrs (_: sys: sys.config.my.ip.tailscale) evaledSystems)); - systemExporters = builtins.listToAttrs (builtins.concatLists (lib.mapAttrsToList (sysName: sys: lib.mapAttrsToList (exporterName: exporter: let jobName = "${sysName}/exporters/${exporterName}"; in lib.nameValuePair jobName { - job_name = jobName; - static_configs = [{ - targets = ["${sysName}:${toString exporter.port}"]; - labels = { - system = sysName; - exporter = exporterName; + systemExporters = let + exportersForSystem = sysName: sys: let + mkExporter = exporterName: exporterPort: let jobName = "${sysName}/exporters/${exporterName}"; in lib.nameValuePair jobName { + job_name = jobName; + static_configs = [{ + targets = ["${sysName}:${toString exporterPort}"]; + labels = { + system = sysName; + exporter = exporterName; + }; + }]; }; - }]; - }) (lib.filterAttrs (_: exporter: exporter.enable) sys.config.services.prometheus.exporters)) evaledSystems)); + stockExporters = lib.mapAttrsToList (exporterName: exporter: mkExporter exporterName exporter.port) (lib.filterAttrs (_: exporter: exporter.enable) sys.config.services.prometheus.exporters); + customExporters = lib.mapAttrsToList mkExporter sys.config.my.prometheus.additionalExporterPorts; + in + stockExporters ++ customExporters; + in + builtins.listToAttrs (builtins.concatLists (lib.mapAttrsToList exportersForSystem evaledSystems)); in systemDrvs // { systems = systemDrvs; systemExporters = systemExporters; diff --git a/ops/nixos/lib/common.nix b/ops/nixos/lib/common.nix index e0a19b42e8..82ee56ca9d 100644 --- a/ops/nixos/lib/common.nix +++ b/ops/nixos/lib/common.nix @@ -17,6 +17,10 @@ in type = lib.types.nullOr lib.types.anything; default = null; }; + options.my.prometheus.additionalExporterPorts = lib.mkOption { + type = lib.types.attrsOf lib.types.port; + default = {}; + }; options.my.ip.tailscale = lib.mkOption { type = lib.types.nullOr lib.types.string; diff --git a/ops/nixos/swann/default.nix b/ops/nixos/swann/default.nix index 538e16a76f..ca0d1fa4ac 100644 --- a/ops/nixos/swann/default.nix +++ b/ops/nixos/swann/default.nix @@ -209,6 +209,7 @@ in { } ''; }; + my.prometheus.additionalExporterPorts.coredns = 9153; networking.resolvconf.extraConfig = '' name_servers='127.0.0.53' '';