From 550d1c05e17345adadd0a1665705623bbd95473b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 16 Sep 2024 15:10:54 +0300 Subject: [PATCH] ping: relabel --- hosts/fwminex/configuration.nix | 39 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/hosts/fwminex/configuration.nix b/hosts/fwminex/configuration.nix index 2c39840..2937f6a 100644 --- a/hosts/fwminex/configuration.nix +++ b/hosts/fwminex/configuration.nix @@ -344,24 +344,31 @@ in scrapeConfigs = [ - { - job_name = "ping"; - static_configs = [ - ( - let - port = toString config.services.prometheus.exporters.ping.port; - in + ( + let + port = toString config.services.prometheus.exporters.ping.port; + hosts = [ + "fwminex.servers.jakst" + "fra1-b.servers.jakst" + "vno1-gdrx.motiejus.jakst" + ]; + in + + { + job_name = "ping"; + relabel_configs = map (hostname: { + source_labels = [ "__address__" ]; + regex = "${myData.hosts.${hostname}.jakstIP}:${port}"; + replacement = "${hostname}:${port}"; + target_label = "__address__"; + }) hosts; + static_configs = [ { - targets = [ - "127.0.0.1:${port}" - "${myData.hosts."fwminex.servers.jakst".jakstIP}:${port}" - "${myData.hosts."fra1-b.servers.jakst".jakstIP}:${port}" - "${myData.hosts."vno1-gdrx.motiejus.jakst".jakstIP}:${port}" - ]; + targets = [ "127.0.0.1:${port}" ] ++ map (host: "${myData.hosts.${host}.jakstIP}:${port}") hosts; } - ) - ]; - } + ]; + } + ) { job_name = "prometheus"; static_configs = [ { targets = [ "127.0.0.1:${toString myData.ports.prometheus}" ]; } ];