summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorFlakebi <flakebi@t-online.de>2021-05-18 22:23:49 +0200
committerRaphael Megzari <raphael@megzari.com>2021-06-06 08:17:25 +0900
commit5e5a3c39edfbb3022c2c8cdffd6f291471437481 (patch)
treef2b737baa40e4d928f69289ef0f292f282338979 /nixos
parent0d70bbcda446223255fdd0218301e71cf5b9bbdc (diff)
downloadnixpkgs-5e5a3c39edfbb3022c2c8cdffd6f291471437481.tar
nixpkgs-5e5a3c39edfbb3022c2c8cdffd6f291471437481.tar.gz
nixpkgs-5e5a3c39edfbb3022c2c8cdffd6f291471437481.tar.bz2
nixpkgs-5e5a3c39edfbb3022c2c8cdffd6f291471437481.tar.lz
nixpkgs-5e5a3c39edfbb3022c2c8cdffd6f291471437481.tar.xz
nixpkgs-5e5a3c39edfbb3022c2c8cdffd6f291471437481.tar.zst
nixpkgs-5e5a3c39edfbb3022c2c8cdffd6f291471437481.zip
nixos/prometheus: add process exporter
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters.nix1
-rw-r--r--nixos/modules/services/monitoring/prometheus/exporters/process.nix48
-rw-r--r--nixos/tests/prometheus-exporters.nix19
3 files changed, 68 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix
index 9fcfe7b52e0..212ba06ef75 100644
--- a/nixos/modules/services/monitoring/prometheus/exporters.nix
+++ b/nixos/modules/services/monitoring/prometheus/exporters.nix
@@ -51,6 +51,7 @@ let
     "pihole"
     "postfix"
     "postgres"
+    "process"
     "py-air-control"
     "redis"
     "rspamd"
diff --git a/nixos/modules/services/monitoring/prometheus/exporters/process.nix b/nixos/modules/services/monitoring/prometheus/exporters/process.nix
new file mode 100644
index 00000000000..e3b3d18367f
--- /dev/null
+++ b/nixos/modules/services/monitoring/prometheus/exporters/process.nix
@@ -0,0 +1,48 @@
+{ config, lib, pkgs, options }:
+
+with lib;
+
+let
+  cfg = config.services.prometheus.exporters.process;
+  configFile = pkgs.writeText "process-exporter.yaml" (builtins.toJSON cfg.settings);
+in
+{
+  port = 9256;
+  extraOpts = {
+    settings.process_names = mkOption {
+      type = types.listOf types.anything;
+      default = {};
+      example = literalExample ''
+        {
+          process_names = [
+            # Remove nix store path from process name
+            { name = "{{.Matches.Wrapped}} {{ .Matches.Args }}"; cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ]; }
+          ];
+        }
+      '';
+      description = ''
+        All settings expressed as an Nix attrset.
+
+        Check the official documentation for the corresponding YAML
+        settings that can all be used here: <link xlink:href="https://github.com/ncabatoff/process-exporter" />
+      '';
+    };
+  };
+  serviceOpts = {
+    serviceConfig = {
+      DynamicUser = false;
+      ExecStart = ''
+        ${pkgs.prometheus-process-exporter}/bin/process-exporter \
+          --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
+          --config.path ${configFile} \
+          ${concatStringsSep " \\\n  " cfg.extraFlags}
+      '';
+      NoNewPrivileges = true;
+      ProtectHome = true;
+      ProtectSystem = true;
+      ProtectKernelTunables = true;
+      ProtectKernelModules = true;
+      ProtectControlGroups = true;
+    };
+  };
+}
diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index e3bfff218ad..d13058dff4c 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -864,6 +864,25 @@ let
       '';
     };
 
+    process = {
+      exporterConfig = {
+        enable = true;
+        settings.process_names = [
+          # Remove nix store path from process name
+          { name = "{{.Matches.Wrapped}} {{ .Matches.Args }}"; cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ]; }
+        ];
+      };
+      exporterTest = ''
+        wait_for_unit("prometheus-process-exporter.service")
+        wait_for_open_port(9256)
+        wait_until_succeeds(
+            "curl -sSf localhost:9256/metrics | grep -q '{}'".format(
+                'namedprocess_namegroup_cpu_seconds_total{groupname="process-exporter '
+            )
+        )
+      '';
+    };
+
     py-air-control = {
       nodeName = "py_air_control";
       exporterConfig = {