ops/nixos: add ability to define additional things to be scraped, use this for coredns

This commit is contained in:
Luke Granger-Brown 2020-11-18 02:02:23 +00:00
parent 588a47e97f
commit 26352c7065
3 changed files with 22 additions and 9 deletions

View file

@ -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 {
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 exporter.port}"];
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;

View file

@ -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;

View file

@ -209,6 +209,7 @@ in {
}
'';
};
my.prometheus.additionalExporterPorts.coredns = 9153;
networking.resolvconf.extraConfig = ''
name_servers='127.0.0.53'
'';