From 4bfe837a586c8ecc1bc577207faf15c152dd1e22 Mon Sep 17 00:00:00 2001 From: Amanda Cameron Date: Fri, 19 Nov 2021 13:09:56 -0500 Subject: [PATCH 1/2] nixos/prometheus/systemd: Implement the extraFlags config option. --- .../services/monitoring/prometheus/exporters/systemd.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/monitoring/prometheus/exporters/systemd.nix b/nixos/modules/services/monitoring/prometheus/exporters/systemd.nix index c0a50f07d717..2edd1de83e1b 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/systemd.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/systemd.nix @@ -11,7 +11,7 @@ in { serviceConfig = { ExecStart = '' ${pkgs.prometheus-systemd-exporter}/bin/systemd_exporter \ - --web.listen-address ${cfg.listenAddress}:${toString cfg.port} + --web.listen-address ${cfg.listenAddress}:${toString cfg.port} ${concatStringsSep " " cfg.extraFlags} ''; RestrictAddressFamilies = [ # Need AF_UNIX to collect data From f1bcb88bf6b075856570c433014ed123d53abdc0 Mon Sep 17 00:00:00 2001 From: Amanda Cameron Date: Fri, 19 Nov 2021 13:52:49 -0500 Subject: [PATCH 2/2] nixos/tests/prometheus-exporters: Add a test to cover a regression. --- nixos/tests/prometheus-exporters.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index 38b93c4087c0..55877b0e10d6 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -1123,6 +1123,10 @@ let systemd = { exporterConfig = { enable = true; + + extraFlags = [ + "--collector.enable-restart-count" + ]; }; metricProvider = { }; exporterTest = '' @@ -1133,6 +1137,11 @@ let 'systemd_unit_state{name="basic.target",state="active",type="target"} 1' ) ) + succeed( + "curl -sSf localhost:9558/metrics | grep '{}'".format( + 'systemd_service_restart_total{state="prometheus-systemd-exporter.service"} 0' + ) + ) ''; };