nixos/prometheus: add process exporter

authored by Flakebi and committed by Raphael Megzari 5e5a3c39 0d70bbcd

+71 -1
+1
nixos/modules/services/monitoring/prometheus/exporters.nix
··· 51 51 "pihole" 52 52 "postfix" 53 53 "postgres" 54 + "process" 54 55 "py-air-control" 55 56 "redis" 56 57 "rspamd"
+48
nixos/modules/services/monitoring/prometheus/exporters/process.nix
··· 1 + { config, lib, pkgs, options }: 2 + 3 + with lib; 4 + 5 + let 6 + cfg = config.services.prometheus.exporters.process; 7 + configFile = pkgs.writeText "process-exporter.yaml" (builtins.toJSON cfg.settings); 8 + in 9 + { 10 + port = 9256; 11 + extraOpts = { 12 + settings.process_names = mkOption { 13 + type = types.listOf types.anything; 14 + default = {}; 15 + example = literalExample '' 16 + { 17 + process_names = [ 18 + # Remove nix store path from process name 19 + { name = "{{.Matches.Wrapped}} {{ .Matches.Args }}"; cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ]; } 20 + ]; 21 + } 22 + ''; 23 + description = '' 24 + All settings expressed as an Nix attrset. 25 + 26 + Check the official documentation for the corresponding YAML 27 + settings that can all be used here: <link xlink:href="https://github.com/ncabatoff/process-exporter" /> 28 + ''; 29 + }; 30 + }; 31 + serviceOpts = { 32 + serviceConfig = { 33 + DynamicUser = false; 34 + ExecStart = '' 35 + ${pkgs.prometheus-process-exporter}/bin/process-exporter \ 36 + --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ 37 + --config.path ${configFile} \ 38 + ${concatStringsSep " \\\n " cfg.extraFlags} 39 + ''; 40 + NoNewPrivileges = true; 41 + ProtectHome = true; 42 + ProtectSystem = true; 43 + ProtectKernelTunables = true; 44 + ProtectKernelModules = true; 45 + ProtectControlGroups = true; 46 + }; 47 + }; 48 + }
+19
nixos/tests/prometheus-exporters.nix
··· 864 864 ''; 865 865 }; 866 866 867 + process = { 868 + exporterConfig = { 869 + enable = true; 870 + settings.process_names = [ 871 + # Remove nix store path from process name 872 + { name = "{{.Matches.Wrapped}} {{ .Matches.Args }}"; cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ]; } 873 + ]; 874 + }; 875 + exporterTest = '' 876 + wait_for_unit("prometheus-process-exporter.service") 877 + wait_for_open_port(9256) 878 + wait_until_succeeds( 879 + "curl -sSf localhost:9256/metrics | grep -q '{}'".format( 880 + 'namedprocess_namegroup_cpu_seconds_total{groupname="process-exporter ' 881 + ) 882 + ) 883 + ''; 884 + }; 885 + 867 886 py-air-control = { 868 887 nodeName = "py_air_control"; 869 888 exporterConfig = {
+3 -1
pkgs/servers/monitoring/prometheus/process-exporter.nix
··· 1 - { lib, buildGoModule, fetchFromGitHub }: 1 + { lib, buildGoModule, fetchFromGitHub, nixosTests }: 2 2 3 3 buildGoModule rec { 4 4 pname = "process-exporter"; ··· 18 18 ''; 19 19 20 20 doCheck = true; 21 + 22 + passthru.tests = { inherit (nixosTests.prometheus-exporters) process; }; 21 23 22 24 meta = with lib; { 23 25 description = "Prometheus exporter that mines /proc to report on selected processes";