diff --git a/hosts/cube/nextcloud/default.nix b/hosts/cube/nextcloud/default.nix index 02dbe0f..1a37e95 100644 --- a/hosts/cube/nextcloud/default.nix +++ b/hosts/cube/nextcloud/default.nix @@ -5,8 +5,6 @@ let fqdn = "cloud.${domain}"; - prometheusPort = 9060; - nextcloudPackage = pkgs.nextcloud28; in systemConfiguration { secrets.nextcloudPassword = { @@ -18,26 +16,12 @@ in systemConfiguration { owner = "nextcloud-exporter"; }; - services.prometheus = { - exporters.nextcloud = enabled { - listenAddress = "[::1]"; - port = prometheusPort; + services.prometheus.exporters.nextcloud = enabled { + listenAddress = "[::]"; - username = "admin"; - url = "https://${fqdn}"; - passwordFile = config.secrets.nextcloudExporterPassword.path; - }; - - scrapeConfigs = [{ - job_name = "nextcloud"; - - static_configs = [{ - labels.job = "nextcloud"; - targets = [ - "[::1]:${toString prometheusPort}" - ]; - }]; - }]; + username = "admin"; + url = "https://${fqdn}"; + passwordFile = config.secrets.nextcloudExporterPassword.path; }; services.postgresql = { diff --git a/hosts/cube/nginx.nix b/hosts/cube/nginx.nix index a130f07..183f6d2 100644 --- a/hosts/cube/nginx.nix +++ b/hosts/cube/nginx.nix @@ -1,27 +1,13 @@ { lib, pkgs, ... }: with lib; -let - prometheusPort = 9030; -in systemConfiguration { +systemConfiguration { networking.firewall = { allowedTCPPorts = [ 443 80 ]; allowedUDPPorts = [ 443 ]; }; - services.prometheus = { - exporters.nginx = enabled { - listenAddress = "[::1]"; - port = prometheusPort; - }; - - scrapeConfigs = [{ - job_name = "nginx"; - - static_configs = [{ - labels.job = "nginx"; - targets = [ "[::1]:${toString prometheusPort}" ]; - }]; - }]; + services.prometheus.exporters.nginx = enabled { + listenAddress = "[::]"; }; services.nginx = enabled { diff --git a/hosts/cube/postgresql.nix b/hosts/cube/postgresql.nix index 935ad74..a09164a 100644 --- a/hosts/cube/postgresql.nix +++ b/hosts/cube/postgresql.nix @@ -1,23 +1,9 @@ { lib, pkgs, ... }: with lib; merge -(let - prometheusPort = 9020; -in systemConfiguration { - services.prometheus = { - exporters.postgres = enabled { - listenAddress = "[::1]"; - port = prometheusPort; - runAsLocalSuperUser = true; - }; - - scrapeConfigs = [{ - job_name = "postgres"; - - static_configs = [{ - labels.job = "postgres"; - targets = [ "[::1]:${toString prometheusPort}" ]; - }]; - }]; +(systemConfiguration { + services.prometheus.exporters.postgres = enabled { + listenAddress = "[::]"; + runAsLocalSuperUser = true; }; services.postgresql = enabled { diff --git a/hosts/cube/prometheus.nix b/hosts/cube/prometheus.nix index 556c805..ba497aa 100644 --- a/hosts/cube/prometheus.nix +++ b/hosts/cube/prometheus.nix @@ -1,15 +1,11 @@ -{ lib, ... }: with lib; +{ self, config, lib, ... }: with lib; -let - port = 9000; - - nodeExporterPort = 9010; -in systemConfiguration { +systemConfiguration { services.grafana.provision.datasources.settings = { datasources = [{ name = "Prometheus"; type = "prometheus"; - url = "http://[::1]:${toString port}"; + url = "http://[::1]:${toString config.services.prometheus.port}"; orgId = 1; }]; @@ -21,23 +17,20 @@ in systemConfiguration { }; services.prometheus = enabled { - inherit port; - + listenAddress = "[::]"; retentionTime = "1w"; - exporters.node = enabled { - enabledCollectors = [ "processes" "systemd" ]; - listenAddress = "[::1]"; - port = nodeExporterPort; - }; + scrapeConfigs = with lib; let + configToScrapeConfig = name: { config, ... }: pipe config.services.prometheus.exporters [ + (filterAttrs (_: value: value.enable or false)) + (mapAttrsToList (expName: expConfig: { + job_name = "${expName}-${name}"; - scrapeConfigs = [{ - job_name = "node"; - - static_configs = [{ - labels.job = "node"; - targets = [ "[::1]:${toString nodeExporterPort}" ]; - }]; - }]; + static_configs = [{ + targets = [ "${name}:${toString expConfig.port}" ]; + }]; + })) + ]; + in flatten (mapAttrsToList configToScrapeConfig self.nixosConfigurations); }; } diff --git a/hosts/disk/mail/default.nix b/hosts/disk/mail/default.nix index 6c0151c..8513b04 100644 --- a/hosts/disk/mail/default.nix +++ b/hosts/disk/mail/default.nix @@ -4,27 +4,11 @@ let inherit (config.networking) domain; fqdn = "mail.${domain}"; - - prometheusPort = 9040; in systemConfiguration { secrets.mailPassword.file = ./password.hash.age; - services.prometheus = { - exporters.postfix = enabled { - listenAddress = "[::1]"; - port = prometheusPort; - }; - - scrapeConfigs = [{ - job_name = "postfix"; - - static_configs = [{ - labels.job = "postfix"; - targets = [ - "[::1]:${toString prometheusPort}" - ]; - }]; - }]; + services.prometheus.exporters.postfix = enabled { + listenAddress = "[::]"; }; mailserver = enabled { diff --git a/modules/endlessh-go.nix b/modules/endlessh-go.nix index b60da92..8623e12 100644 --- a/modules/endlessh-go.nix +++ b/modules/endlessh-go.nix @@ -2,24 +2,9 @@ let fakeSSHPort = 22; - prometheusPort = 9050; in serverSystemConfiguration { - services.prometheus = { - exporters.endlessh-go = enabled { - listenAddress = "[::1]"; - port = prometheusPort; - }; - - scrapeConfigs = [{ - job_name = "endlessh-go"; - - static_configs = [{ - labels.job = "endlessh-go"; - targets = [ - "[::1]:${toString prometheusPort}" - ]; - }]; - }]; + services.prometheus.exporters.endlessh-go = enabled { + listenAddress = "[::]"; }; # `services.endlessh-go.openFirewall` exposes both the Prometheus diff --git a/modules/node-exporter.nix b/modules/node-exporter.nix new file mode 100644 index 0000000..8299357 --- /dev/null +++ b/modules/node-exporter.nix @@ -0,0 +1,8 @@ +{ lib, ... }: with lib; + +serverSystemConfiguration { + services.prometheus.exporters.node = enabled { + enabledCollectors = [ "processes" "systemd" ]; + listenAddress = "[::]"; + }; +} diff --git a/options/endlessh-go-exporter-alias.nix b/options/endlessh-go-exporter-alias.nix index e9e6af4..e04333c 100644 --- a/options/endlessh-go-exporter-alias.nix +++ b/options/endlessh-go-exporter-alias.nix @@ -5,8 +5,18 @@ # This works, however. { config, lib, ... }: { - options.services.prometheus.exporters.endlessh-go = lib.mkOption { - default = {}; + options.services.prometheus.exporters.endlessh-go = { + enable = lib.mkEnableOption (lib.mdDoc "Prometheus integration"); + + listenAddress = lib.mkOption { + type = lib.types.str; + default = "0.0.0.0"; + }; + + port = lib.mkOption { + type = lib.types.port; + default = 2112; + }; }; config.services.endlessh-go.prometheus = config.services.prometheus.exporters.endlessh-go;