From 7b804450a31610c8d100c70fa9647ba2ac7e67cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Fri, 13 Feb 2026 23:40:14 +0100 Subject: [PATCH] promtail: add hostname/tier/role labels and journal priority level mapping Align Promtail labels with Prometheus by adding hostname, tier, and role static labels to both journal and varlog scrape configs. Add pipeline stages to map journal PRIORITY field to a level label for reliable severity filtering across the fleet. Co-Authored-By: Claude Opus 4.6 --- system/monitoring/logs.nix | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/system/monitoring/logs.nix b/system/monitoring/logs.nix index 2d5c131..68d9cac 100644 --- a/system/monitoring/logs.nix +++ b/system/monitoring/logs.nix @@ -1,4 +1,12 @@ -{ config, ... }: +{ config, lib, ... }: +let + hostLabels = { + hostname = config.networking.hostName; + tier = config.homelab.host.tier; + } // lib.optionalAttrs (config.homelab.host.role != null) { + role = config.homelab.host.role; + }; +in { # Configure journald services.journald = { @@ -32,17 +40,26 @@ json = true; labels = { job = "systemd-journal"; - }; + } // hostLabels; }; relabel_configs = [ { source_labels = [ "__journal__systemd_unit" ]; target_label = "systemd_unit"; } + ]; + pipeline_stages = [ + # Extract PRIORITY from journal JSON + { json.expressions.priority = "PRIORITY"; } + # Map numeric PRIORITY to level name { - source_labels = [ "__journal__hostname" ]; - target_label = "host"; + template = { + source = "priority"; + template = ''{{ if or (eq .Value "0") (eq .Value "1") (eq .Value "2") }}critical{{ else if eq .Value "3" }}error{{ else if eq .Value "4" }}warning{{ else if eq .Value "5" }}notice{{ else if eq .Value "6" }}info{{ else if eq .Value "7" }}debug{{ end }}''; + }; } + # Attach as level label + { labels.level = "priority"; } ]; } { @@ -53,8 +70,7 @@ labels = { job = "varlog"; __path__ = "/var/log/**/*.log"; - hostname = "${config.networking.hostName}"; - }; + } // hostLabels; } ]; }