grafana-agent: make bagel.monitoring.grafana-agent.exporters an attrset

This allows us to use multiple jobs, one for each additional exporter,
and set their `job_name` accordingly.

`job_name` is exported as `job` label on the resulting metrics.
This allows us to quickly get an understanding what metrics of an
exporter are actually available by simply filtering all metrics by
`{job="$jobname"}`
This commit is contained in:
emily 2024-07-08 00:34:30 +02:00 committed by K900
parent db8c831c2f
commit 8d2a367e92
4 changed files with 18 additions and 18 deletions

View file

@ -13,14 +13,20 @@ in
enable = (mkEnableOption "Grafana Agent") // { default = true; }; enable = (mkEnableOption "Grafana Agent") // { default = true; };
exporters = mkOption { exporters = mkOption {
description = "List of all exporters to scrape"; description = ''
type = types.listOf (types.submodule { Set of additional exporters to scrape.
The attribute name will be used as `job_name`
internally, which ends up exported as `job` label
on all metrics of that exporter.
'';
type = types.attrsOf (types.submodule {
options.port = mkOption { options.port = mkOption {
description = "Exporter port"; description = "Exporter port";
type = types.int; type = types.int;
}; };
}); });
default = []; default = {};
}; };
}; };
@ -45,14 +51,12 @@ in
configs = [ configs = [
{ {
name = config.networking.hostName; name = config.networking.hostName;
scrape_configs = [ scrape_configs = lib.mapAttrsToList (name: value: {
{ job_name = name;
job_name = config.networking.hostName; static_configs = [
static_configs = [ { targets = "localhost:" + (toString value.port); }
{ targets = map (e: "localhost:" + (toString e.port)) config.bagel.monitoring.grafana-agent.exporters; } ];
]; }) config.bagel.monitoring.grafana-agent.exporters;
}
];
} }
]; ];
}; };

View file

@ -17,6 +17,6 @@ in
listenAddress = "0.0.0.0"; listenAddress = "0.0.0.0";
}; };
bagel.monitoring.grafana-agent.exporters = [ { port = 9102; } ]; bagel.monitoring.grafana-agent.exporters.cadvisor.port = 9102;
}; };
} }

View file

@ -30,8 +30,6 @@ in
]; ];
}; };
bagel.monitoring.grafana-agent.exporters = [ bagel.monitoring.grafana-agent.exporters.nginxlog.port = 9103;
{ port = 9103; }
];
}; };
} }

View file

@ -24,8 +24,6 @@ in
services.postgresql.settings.shared_preload_libraries = "pg_stat_statements"; services.postgresql.settings.shared_preload_libraries = "pg_stat_statements";
bagel.monitoring.grafana-agent.exporters = [ bagel.monitoring.grafana-agent.exporters.postgres.port = 9104;
{ port = 9104; }
];
}; };
} }