From 61bbceb2cfe76a0e72734f266aed6426e0ec8eec Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Tue, 10 Sep 2024 16:34:58 +0700 Subject: [PATCH] prometheus: added but not enabled yet --- options/services.nix | 4 ++ system/services/telemetry/alloy.nix | 1 - system/services/telemetry/default.nix | 1 + system/services/telemetry/prometheus.nix | 50 ++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 system/services/telemetry/prometheus.nix diff --git a/options/services.nix b/options/services.nix index 2b34506..b132526 100644 --- a/options/services.nix +++ b/options/services.nix @@ -55,6 +55,10 @@ in type = types.bool; default = config.profile.services.telemetry.enable; }; + prometheus.enable = mkOption { + type = types.bool; + default = config.profile.services.telemetry.enable; + }; }; }; } diff --git a/system/services/telemetry/alloy.nix b/system/services/telemetry/alloy.nix index 702cad9..250fb2d 100644 --- a/system/services/telemetry/alloy.nix +++ b/system/services/telemetry/alloy.nix @@ -3,7 +3,6 @@ let cfg = config.profile.services.telemetry.alloy; webguiListenAddress = "0.0.0.0:5319"; domain = "alloy.tigor.web.id"; - inherit (lib.strings) optionalString; in { imports = [ diff --git a/system/services/telemetry/default.nix b/system/services/telemetry/default.nix index 62213dd..1a0adad 100644 --- a/system/services/telemetry/default.nix +++ b/system/services/telemetry/default.nix @@ -6,5 +6,6 @@ ./tempo.nix ./alloy.nix ./mimir.nix + ./prometheus.nix ]; } diff --git a/system/services/telemetry/prometheus.nix b/system/services/telemetry/prometheus.nix new file mode 100644 index 0000000..706d655 --- /dev/null +++ b/system/services/telemetry/prometheus.nix @@ -0,0 +1,50 @@ +{ config, lib, ... }: +let + cfg = config.profile.services.telemetry.prometheus; + inherit (lib) mkIf; +in +{ + config = mkIf cfg.enable { + services.prometheus = { + enable = false; + port = 0; # Random + enableAgentMode = true; + globalConfig = { + external_labels = { + instance = "homeserver"; + }; + }; + remoteWrite = + let + mimirServer = config.services.mimir.configuration.server; + in + [ + { + url = "http://${mimirServer.http_listen_address}:${toString mimirServer.http_listen_port}/api/v1/push"; + } + ]; + scrapeConfigs = [ + { + job_name = "systemd"; + static_configs = [{ + labels = { + job = "systemd"; + }; + targets = + let + systemdExporter = config.services.prometheus.exporters.systemd; + in + [ + "${systemdExporter.listenAddress}:${toString systemdExporter.port}" + ]; + }]; + } + ]; + exporters = { + systemd = { + enable = true; + }; + }; + }; + }; +}