From 69c4138459c39e9e6503f66062e04d88704b623d Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Tue, 20 Aug 2024 12:15:39 +0200 Subject: [PATCH] renge/prometheus: Use common relabel config for VPN --- machines/renge/services/prometheus.nix | 41 ++++++++------------------ 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/machines/renge/services/prometheus.nix b/machines/renge/services/prometheus.nix index c10866d..68fd331 100644 --- a/machines/renge/services/prometheus.nix +++ b/machines/renge/services/prometheus.nix @@ -8,6 +8,12 @@ let mkStaticTargets = targets: lib.singleton { inherit targets; }; mkStaticTarget = target: mkStaticTargets (lib.singleton target); + + relabelVpnConfig = { + target_label = "instance"; + source_labels = lib.singleton "__address__"; + regex = "(.*)\\.vpn\\.sbruder\\.de:[0-9]*"; + }; in { services.prometheus = { @@ -77,11 +83,7 @@ in "yuzuru.vpn.sbruder.de:9100" "koyomi.vpn.sbruder.de:9100" ]; - relabel_configs = lib.singleton { - target_label = "instance"; - source_labels = lib.singleton "__address__"; - regex = "(.*)\\.vpn\\.sbruder\\.de:9100"; - }; + relabel_configs = lib.singleton relabelVpnConfig; } { job_name = "smartctl"; @@ -93,11 +95,7 @@ in "shinobu.vpn.sbruder.de:9633" "koyomi.vpn.sbruder.de:9633" ]; - relabel_configs = lib.singleton { - target_label = "instance"; - source_labels = lib.singleton "__address__"; - regex = "(.*)\\.vpn\\.sbruder\\.de:9633"; - }; + relabel_configs = lib.singleton relabelVpnConfig; } { job_name = "qbittorrent"; @@ -105,11 +103,7 @@ in "fuuko.vpn.sbruder.de:9561" "nazuna.vpn.sbruder.de:9561" ]; - relabel_configs = lib.singleton { - target_label = "instance"; - source_labels = lib.singleton "__address__"; - regex = "(.*)\\.vpn\\.sbruder\\.de:9561"; - }; + relabel_configs = lib.singleton relabelVpnConfig; } ( let @@ -128,10 +122,7 @@ in { job_name = "dnsmasq"; static_configs = mkStaticTarget "shinobu.vpn.sbruder.de:${toString config.services.prometheus.exporters.dnsmasq.port}"; - relabel_configs = lib.singleton { - target_label = "instance"; - replacement = "shinobu"; - }; + relabel_configs = lib.singleton relabelVpnConfig; } { job_name = "hcloud"; @@ -158,11 +149,7 @@ in "okarin.vpn.sbruder.de:9433" "yuzuru.vpn.sbruder.de:9433" ]; - relabel_configs = lib.singleton { - target_label = "instance"; - source_labels = lib.singleton "__address__"; - regex = "(.*)\\.vpn\\.sbruder\\.de:9433"; - }; + relabel_configs = lib.singleton relabelVpnConfig; } { job_name = "snmp"; @@ -193,11 +180,7 @@ in static_configs = mkStaticTargets [ "koyomi.vpn.sbruder.de:8404" ]; - relabel_configs = lib.singleton { - target_label = "instance"; - source_labels = lib.singleton "__address__"; - regex = "(.*)\\.vpn\\.sbruder\\.de:8404"; - }; + relabel_configs = lib.singleton relabelVpnConfig; } ];