exporters.nix (3120B)
1 { 2 config, 3 lib, 4 pkgs, 5 ... 6 }: let 7 cfg = config.services.haravara.monitoring; 8 in { 9 options.services.haravara.monitoring.exporters = { 10 enable = lib.mkEnableOption "Enable node and systemd Prometheus exporters" // {default = true;}; 11 extraNodeStaticConfigs = lib.mkOption { 12 type = lib.types.listOf lib.types.attrs; 13 default = []; 14 description = "Additional static_configs appended to the node_exporter job"; 15 }; 16 extraSystemdStaticConfigs = lib.mkOption { 17 type = lib.types.listOf lib.types.attrs; 18 default = []; 19 description = "Additional static_configs appended to the systemd_exporter job"; 20 }; 21 blackbox = { 22 enable = lib.mkEnableOption "Blackbox Prometheus exporter for endpoint probing"; 23 port = lib.mkOption { 24 type = lib.types.port; 25 default = 9115; 26 description = "Port for the blackbox exporter to listen on"; 27 }; 28 modules = lib.mkOption { 29 type = lib.types.attrs; 30 default = { 31 http = { 32 prober = "http"; 33 timeout = "5s"; 34 http = { 35 fail_if_not_ssl = true; 36 valid_status_codes = [200 301 302 401 403 404]; 37 }; 38 }; 39 tcp_connect = { 40 prober = "tcp"; 41 timeout = "5s"; 42 }; 43 }; 44 description = "Blackbox exporter probe modules"; 45 }; 46 http_targets = lib.mkOption { 47 type = lib.types.listOf lib.types.str; 48 default = []; 49 }; 50 tcp_targets = lib.mkOption { 51 type = lib.types.listOf lib.types.str; 52 default = []; 53 }; 54 }; 55 }; 56 57 config = lib.mkIf (cfg.enable && cfg.exporters.enable) { 58 services.prometheus.exporters = { 59 node = { 60 enable = true; 61 listenAddress = "127.0.0.1"; 62 enabledCollectors = ["systemd"]; 63 port = 9100; 64 }; 65 66 systemd = { 67 enable = true; 68 listenAddress = "127.0.0.1"; 69 port = 9558; 70 extraFlags = [ 71 "--systemd.collector.unit-exclude=.*\\\\.(mount|slice|scope|target|device|path|timer|automount|socket|swap)" 72 ]; 73 }; 74 75 blackbox = lib.mkIf cfg.exporters.blackbox.enable { 76 enable = true; 77 listenAddress = "127.0.0.1"; 78 port = cfg.exporters.blackbox.port; 79 configFile = (pkgs.formats.yaml {}).generate "blackbox.yml" { 80 modules = cfg.exporters.blackbox.modules; 81 }; 82 }; 83 }; 84 85 systemd.services = { 86 prometheus-node-exporter.serviceConfig = { 87 RestrictNamespaces = lib.mkForce false; 88 RestrictAddressFamilies = lib.mkForce ["AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK"]; 89 DynamicUser = lib.mkForce false; 90 User = lib.mkForce "root"; 91 Group = lib.mkForce "root"; 92 }; 93 94 prometheus-systemd-exporter.serviceConfig = { 95 RestrictNamespaces = lib.mkForce false; 96 RestrictAddressFamilies = lib.mkForce ["AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK"]; 97 DynamicUser = lib.mkForce false; 98 User = lib.mkForce "root"; 99 Group = lib.mkForce "root"; 100 }; 101 }; 102 }; 103 }