From 30e22dff8d29c29adc1da8c30503eb5cef8ca452 Mon Sep 17 00:00:00 2001 From: clerie Date: Thu, 5 Jan 2023 22:02:48 +0100 Subject: [PATCH] hosts/monitoring-3: use primary fqdn for instance label in prometheus --- hosts/monitoring-3/configuration.nix | 34 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/hosts/monitoring-3/configuration.nix b/hosts/monitoring-3/configuration.nix index 0956bf9..7107daf 100644 --- a/hosts/monitoring-3/configuration.nix +++ b/hosts/monitoring-3/configuration.nix @@ -131,7 +131,14 @@ in { services.prometheus = { enable = true; listenAddress = "[::1]"; - scrapeConfigs = [ + scrapeConfigs = let + relabelAddressToInstance = { + source_labels = [ "__address__" ]; + target_label = "instance"; + regex = ''([\w-]+)\.mon\.clerie\.de\:\d+''; + replacement = "\${1}.net.clerie.de"; + }; + in [ { job_name = "prometheus"; scrape_interval = "20s"; @@ -143,6 +150,9 @@ in { ]; } ]; + relabel_configs = [ + relabelAddressToInstance + ]; } { job_name = "node-exporter"; @@ -155,6 +165,9 @@ in { ++ monitoringTargets; } ]; + relabel_configs = [ + relabelAddressToInstance + ]; } { job_name = "nixos-exporter"; @@ -164,6 +177,9 @@ in { targets = nixosMonitoringTargets; } ]; + relabel_configs = [ + relabelAddressToInstance + ]; } { job_name = "bird-exporter"; @@ -173,6 +189,9 @@ in { targets = birdMonitoringTargets; } ]; + relabel_configs = [ + relabelAddressToInstance + ]; } { job_name = "blackbox_icmp6"; @@ -211,10 +230,7 @@ in { target_label = "__address__"; replacement = "\${1}"; } - { - source_labels = [ "__address__" ]; - target_label = "instance"; - } + relabelAddressToInstance ]; } { @@ -255,10 +271,7 @@ in { target_label = "__address__"; replacement = "\${1}"; } - { - source_labels = [ "__address__" ]; - target_label = "instance"; - } + relabelAddressToInstance ]; } { @@ -297,6 +310,9 @@ in { ]; } ]; + relabel_configs = [ + relabelAddressToInstance + ]; } ]; alertmanagers = [