From f9caa0af7f62f9c4608eb7b7d8608cc96edb6626 Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Mon, 16 Sep 2024 10:32:43 +0700 Subject: [PATCH] caddy: added metrics for caddy access log --- system/services/caddy.nix | 48 +++++++++++++++++++++++++++++ system/services/telemetry/alloy.nix | 4 +++ system/services/telemetry/loki.nix | 2 ++ 3 files changed, 54 insertions(+) diff --git a/system/services/caddy.nix b/system/services/caddy.nix index 577fab2..ef5e004 100644 --- a/system/services/caddy.nix +++ b/system/services/caddy.nix @@ -69,5 +69,53 @@ in ''; }; + environment.etc."alloy/config.alloy".text = + /*hcl*/ '' + local.file_match "caddy_access_log" { + path_targets = [ + { + "__path__" = "/var/log/caddy/*.log", + }, + ] + sync_period = "5s" + } + + loki.source.file "caddy_access_log" { + targets = local.file_match.caddy_access_log.targets + forward_to = [loki.process.caddy_access_log.receiver] + } + + loki.process "caddy_access_log" { + forward_to = [loki.write.default.receiver] + + stage.json { + expressions = { + level = "", + host = "request.host", + method = "request.method", + proto = "request.proto", + } + } + + stage.labels { + values = { + level = "", + host = "", + method = "", + proto = "", + } + } + + stage.label_drop { + values = ["service_name"] + } + + stage.static_labels { + values = { + job = "caddy_access_log", + } + } + } + ''; }; } diff --git a/system/services/telemetry/alloy.nix b/system/services/telemetry/alloy.nix index 250fb2d..3b95a89 100644 --- a/system/services/telemetry/alloy.nix +++ b/system/services/telemetry/alloy.nix @@ -51,6 +51,10 @@ in config.sops.templates."alloy-basic-auth".path ]; + systemd.services.alloy.serviceConfig = { + User = "root"; + }; + environment.etc."alloy/config.alloy".text = let diff --git a/system/services/telemetry/loki.nix b/system/services/telemetry/loki.nix index 7535b54..383bb5b 100644 --- a/system/services/telemetry/loki.nix +++ b/system/services/telemetry/loki.nix @@ -97,6 +97,8 @@ in limits_config = { retention_period = "90d"; + ingestion_burst_size_mb = 64; + ingestion_rate_mb = 32; }; storage_config = {