diff --git a/services/monitoring/agent.nix b/services/monitoring/agent.nix index 3fc2e0d..17274ba 100644 --- a/services/monitoring/agent.nix +++ b/services/monitoring/agent.nix @@ -13,14 +13,20 @@ in enable = (mkEnableOption "Grafana Agent") // { default = true; }; exporters = mkOption { - description = "List of all exporters to scrape"; - type = types.listOf (types.submodule { + description = '' + 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 { description = "Exporter port"; type = types.int; }; }); - default = []; + default = {}; }; }; @@ -45,14 +51,12 @@ in configs = [ { name = config.networking.hostName; - scrape_configs = [ - { - job_name = config.networking.hostName; - static_configs = [ - { targets = map (e: "localhost:" + (toString e.port)) config.bagel.monitoring.grafana-agent.exporters; } - ]; - } - ]; + scrape_configs = lib.mapAttrsToList (name: value: { + job_name = name; + static_configs = [ + { targets = "localhost:" + (toString value.port); } + ]; + }) config.bagel.monitoring.grafana-agent.exporters; } ]; }; diff --git a/services/monitoring/exporters/cadvisor.nix b/services/monitoring/exporters/cadvisor.nix index 285eaae..6f2bfba 100644 --- a/services/monitoring/exporters/cadvisor.nix +++ b/services/monitoring/exporters/cadvisor.nix @@ -17,6 +17,6 @@ in listenAddress = "0.0.0.0"; }; - bagel.monitoring.grafana-agent.exporters = [ { port = 9102; } ]; + bagel.monitoring.grafana-agent.exporters.cadvisor.port = 9102; }; } diff --git a/services/monitoring/exporters/nginx.nix b/services/monitoring/exporters/nginx.nix index 1f190c7..e066c79 100644 --- a/services/monitoring/exporters/nginx.nix +++ b/services/monitoring/exporters/nginx.nix @@ -30,8 +30,6 @@ in ]; }; - bagel.monitoring.grafana-agent.exporters = [ - { port = 9103; } - ]; + bagel.monitoring.grafana-agent.exporters.nginxlog.port = 9103; }; } \ No newline at end of file diff --git a/services/monitoring/exporters/postgres.nix b/services/monitoring/exporters/postgres.nix index 8ce3f45..c6a9469 100644 --- a/services/monitoring/exporters/postgres.nix +++ b/services/monitoring/exporters/postgres.nix @@ -24,8 +24,6 @@ in services.postgresql.settings.shared_preload_libraries = "pg_stat_statements"; - bagel.monitoring.grafana-agent.exporters = [ - { port = 9104; } - ]; + bagel.monitoring.grafana-agent.exporters.postgres.port = 9104; }; } \ No newline at end of file