index f805920c5b87a..b67f41c4fb12c 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -66,6 +66,7 @@ let "nginx" "nginxlog" "node" + "node-cert" "nut" "nvidia-gpu" "pgbouncer" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/node-cert.nix b/nixos/modules/services/monitoring/prometheus/exporters/node-cert.nix new file mode 100644 index 0000000000000..d8b2004e8e857 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/node-cert.nix @@ -0,0 +1,70 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.prometheus.exporters.node-cert; + inherit (lib) mkOption types concatStringsSep; +in +{ + port = 9141; + + extraOpts = { + paths = mkOption { + type = types.listOf types.str; + description = '' + List of paths to search for SSL certificates. + ''; + }; + + excludePaths = mkOption { + type = types.listOf types.str; + description = '' + List of paths to exclute from searching for SSL certificates. + ''; + default = [ ]; + }; + + includeGlobs = mkOption { + type = types.listOf types.str; + description = '' + List files matching a pattern to include. Uses Go blob pattern. + ''; + default = [ ]; + }; + + excludeGlobs = mkOption { + type = types.listOf types.str; + description = '' + List files matching a pattern to include. Uses Go blob pattern. + ''; + default = [ ]; + }; + + user = mkOption { + type = types.str; + description = '' + User owning the certs. + ''; + default = "acme"; + }; + }; + + serviceOpts = { + serviceConfig = { + User = cfg.user; + ExecStart = '' + ${lib.getExe pkgs.prometheus-node-cert-exporter} \ + --listen ${toString cfg.listenAddress}:${toString cfg.port} \ + --path ${concatStringsSep "," cfg.paths} \ + --exclude-path "${concatStringsSep "," cfg.excludePaths}" \ + --include-glob "${concatStringsSep "," cfg.includeGlobs}" \ + --exclude-glob "${concatStringsSep "," cfg.excludeGlobs}" \ + ${concatStringsSep " \\\n " cfg.extraFlags} + ''; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index c15a3fd20b021..f59d61e69b92e 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -1002,6 +1002,49 @@ let ''; }; + node-cert = { + nodeName = "node_cert"; + exporterConfig = { + enable = true; + paths = ["/run/certs"]; + }; + exporterTest = '' + wait_for_unit("prometheus-node-cert-exporter.service") + wait_for_open_port(9141) + wait_until_succeeds( + "curl -sSf http://localhost:9141/metrics | grep 'ssl_certificate_expiry_seconds{.\\+path=\"/run/certs/node-cert\\.cert\".\\+}'" + ) + ''; + + metricProvider = { + system.activationScripts.cert.text = '' + mkdir -p /run/certs + cd /run/certs + + cat >ca.template <