From d2e5cdde64a63d8b5e81473bd83eb0aedac0e577 Mon Sep 17 00:00:00 2001 From: Florian Sesser <florian@private.storage> Date: Wed, 13 Apr 2022 14:01:13 +0000 Subject: [PATCH] Use log retention setting in promtail and loki config --- nixos/modules/monitoring/exporters/promtail.nix | 3 ++- nixos/modules/monitoring/server/loki.nix | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/nixos/modules/monitoring/exporters/promtail.nix b/nixos/modules/monitoring/exporters/promtail.nix index d0a49971..def02568 100644 --- a/nixos/modules/monitoring/exporters/promtail.nix +++ b/nixos/modules/monitoring/exporters/promtail.nix @@ -11,6 +11,7 @@ let cfg = config.services.private-storage.monitoring.exporters.promtail; hostName = config.networking.hostName; + logRetention = toString(config.services.private-storage.monitoring.policy.logRetentionSeconds) + "s"; in { options.services.private-storage.monitoring.exporters.promtail = { @@ -40,7 +41,7 @@ in { services.journald.extraConfig = '' # This tells journald it can discard log files that contain only log # entries that are older than 29 days. - MaxRetentionSec=29day + MaxRetentionSec=${logRetention} # This tells journald to start a new log file once a day. Together with # the MaxRetentionSec setting, this means that entries are kept for diff --git a/nixos/modules/monitoring/server/loki.nix b/nixos/modules/monitoring/server/loki.nix index 491d1a4c..f73720a5 100644 --- a/nixos/modules/monitoring/server/loki.nix +++ b/nixos/modules/monitoring/server/loki.nix @@ -7,7 +7,11 @@ # https://grafana.com/docs/loki/latest/configuration/examples/#complete-local-configyaml # -{ +{ config, ...}: +let + logRetention = toString(config.services.private-storage.monitoring.policy.logRetentionSeconds) + "s"; + +in { config.networking.firewall.interfaces.monitoringvpn.allowedTCPPorts = [ 3100 ]; config.services.loki = { @@ -61,7 +65,7 @@ table_manager = { retention_deletes_enabled = true; - retention_period = "336h"; # two weeks + retention_period = logRetention; }; }; }; -- GitLab