From 096fe1dc0375fdedf6b4cbd33e850bece56e80f6 Mon Sep 17 00:00:00 2001 From: clerie Date: Sun, 1 Jun 2025 14:08:57 +0200 Subject: [PATCH] profiles/monitoring-server: Monitor http --- hosts/monitoring-3/blackbox.nix | 42 +++++++++ hosts/monitoring-3/prometheus.nix | 116 +++++++++++++++++++++++++ profiles/monitoring-server/default.nix | 35 +++++--- 3 files changed, 183 insertions(+), 10 deletions(-) diff --git a/hosts/monitoring-3/blackbox.nix b/hosts/monitoring-3/blackbox.nix index e3023bc..4fa6dd3 100644 --- a/hosts/monitoring-3/blackbox.nix +++ b/hosts/monitoring-3/blackbox.nix @@ -25,6 +25,48 @@ fail_if_not_ssl: true fail_if_body_not_matches_regexp: - "Synapse is running" + headers: + User-Agent: "monitoring.clerie.de, blackbox exporter" + http4: + prober: http + http: + preferred_ip_protocol: ip4 + ip_protocol_fallback: false + fail_if_ssl: true + follow_redirects: false + valid_status_codes: [ 200, 204, 301, 302, 303, 307, 308 ] + headers: + User-Agent: "monitoring.clerie.de, blackbox exporter" + http6: + prober: http + http: + preferred_ip_protocol: ip6 + ip_protocol_fallback: false + fail_if_ssl: true + follow_redirects: false + valid_status_codes: [ 200, 204, 301, 302, 303, 307, 308 ] + headers: + User-Agent: "monitoring.clerie.de, blackbox exporter" + https4: + prober: http + http: + preferred_ip_protocol: ip4 + ip_protocol_fallback: false + fail_if_not_ssl: true + follow_redirects: false + valid_status_codes: [ 200, 204, 301, 302, 303, 307, 308 ] + headers: + User-Agent: "monitoring.clerie.de, blackbox exporter" + https6: + prober: http + http: + preferred_ip_protocol: ip6 + ip_protocol_fallback: false + fail_if_not_ssl: true + follow_redirects: false + valid_status_codes: [ 200, 204, 301, 302, 303, 307, 308 ] + headers: + User-Agent: "monitoring.clerie.de, blackbox exporter" ''; }; } diff --git a/hosts/monitoring-3/prometheus.nix b/hosts/monitoring-3/prometheus.nix index 73b0eab..e305e88 100644 --- a/hosts/monitoring-3/prometheus.nix +++ b/hosts/monitoring-3/prometheus.nix @@ -366,6 +366,122 @@ in { relabelAddressToInstance ]; } + { + job_name = "blackbox_local_http6"; + scrape_interval = "100s"; + metrics_path = "/probe"; + params = { + module = [ "http6" ]; + }; + static_configs = [ + { + targets = config.profiles.clerie.monitoring-server.probeTargets.blackbox-local-http6; + } + ]; + relabel_configs = [ + { + source_labels = [ "__address__" ]; + target_label = "__param_target"; + replacement = "http://\${1}"; + } + { + source_labels = [ "__address__" ]; + target_label = "target"; + } + { + target_label = "__address__"; + replacement = "monitoring-3.mon.clerie.de:9115"; + } + relabelAddressToInstance + ]; + } + { + job_name = "blackbox_local_http4"; + scrape_interval = "100s"; + metrics_path = "/probe"; + params = { + module = [ "http4" ]; + }; + static_configs = [ + { + targets = config.profiles.clerie.monitoring-server.probeTargets.blackbox-local-http4; + } + ]; + relabel_configs = [ + { + source_labels = [ "__address__" ]; + target_label = "__param_target"; + replacement = "http://\${1}"; + } + { + source_labels = [ "__address__" ]; + target_label = "target"; + } + { + target_label = "__address__"; + replacement = "monitoring-3.mon.clerie.de:9115"; + } + relabelAddressToInstance + ]; + } + { + job_name = "blackbox_local_https6"; + scrape_interval = "100s"; + metrics_path = "/probe"; + params = { + module = [ "https6" ]; + }; + static_configs = [ + { + targets = config.profiles.clerie.monitoring-server.probeTargets.blackbox-local-http6; + } + ]; + relabel_configs = [ + { + source_labels = [ "__address__" ]; + target_label = "__param_target"; + replacement = "https://\${1}"; + } + { + source_labels = [ "__address__" ]; + target_label = "target"; + } + { + target_label = "__address__"; + replacement = "monitoring-3.mon.clerie.de:9115"; + } + relabelAddressToInstance + ]; + } + { + job_name = "blackbox_local_https4"; + scrape_interval = "100s"; + metrics_path = "/probe"; + params = { + module = [ "https4" ]; + }; + static_configs = [ + { + targets = config.profiles.clerie.monitoring-server.probeTargets.blackbox-local-http4; + } + ]; + relabel_configs = [ + { + source_labels = [ "__address__" ]; + target_label = "__param_target"; + replacement = "https://\${1}"; + } + { + source_labels = [ "__address__" ]; + target_label = "target"; + } + { + target_label = "__address__"; + replacement = "monitoring-3.mon.clerie.de:9115"; + } + relabelAddressToInstance + ]; + } { job_name = "hydra"; scrape_interval = "20s"; diff --git a/profiles/monitoring-server/default.nix b/profiles/monitoring-server/default.nix index 66be646..d7f911c 100644 --- a/profiles/monitoring-server/default.nix +++ b/profiles/monitoring-server/default.nix @@ -48,6 +48,11 @@ in { clerie-uberspace = mkProbeOption "This target is a uberspace host managed by clerie" {}; http = mkProbeOption "Monitor HTTP" { protocols = mkProtocolsOption; + transport = mkOption { + type = with types; listOf (enum [ "http" "https" ]); + default = [ "http" "https" ]; + description = "HTTP transport modes to monitor"; + }; }; icmp = mkProbeOption "Monitor HTTP" { protocols = mkProtocolsOption; @@ -56,10 +61,12 @@ in { }; probeTargets = mkSubmoduleOption "Target per probe" { - blackbox-http4 = mkTargetsListOption; - blackbox-http6 = mkTargetsListOption; blackbox-icmp4 = mkTargetsListOption; blackbox-icmp6 = mkTargetsListOption; + blackbox-local-http4 = mkTargetsListOption; + blackbox-local-http6 = mkTargetsListOption; + blackbox-local-https4 = mkTargetsListOption; + blackbox-local-https6 = mkTargetsListOption; node-exporter-uberspace = mkTargetsListOption; blackbox-local-synapse = mkTargetsListOption; }; @@ -67,14 +74,6 @@ in { config = { - profiles.clerie.monitoring-server.probeTargets.blackbox-http4 = targetsForProbe "http" (probeConfig: - (listContains "ipv4" probeConfig.protocols) - ); - - profiles.clerie.monitoring-server.probeTargets.blackbox-http6 = targetsForProbe "http" (probeConfig: - (listContains "ipv6" probeConfig.protocols) - ); - profiles.clerie.monitoring-server.probeTargets.blackbox-icmp4 = targetsForProbe "icmp" (probeConfig: (listContains "ipv4" probeConfig.protocols) ); @@ -83,6 +82,22 @@ in { (listContains "ipv6" probeConfig.protocols) ); + profiles.clerie.monitoring-server.probeTargets.blackbox-local-http4 = targetsForProbe "http" (probeConfig: + (listContains "ipv4" probeConfig.protocols) && (listContains "http" probeConfig.transport) + ); + + profiles.clerie.monitoring-server.probeTargets.blackbox-local-http6 = targetsForProbe "http" (probeConfig: + (listContains "ipv6" probeConfig.protocols) && (listContains "http" probeConfig.transport) + ); + + profiles.clerie.monitoring-server.probeTargets.blackbox-local-https4 = targetsForProbe "http" (probeConfig: + (listContains "ipv4" probeConfig.protocols) && (listContains "https" probeConfig.transport) + ); + + profiles.clerie.monitoring-server.probeTargets.blackbox-local-https6 = targetsForProbe "http" (probeConfig: + (listContains "ipv6" probeConfig.protocols) && (listContains "https" probeConfig.transport) + ); + profiles.clerie.monitoring-server.probeTargets.node-exporter-uberspace = targetsForProbe "clerie-uberspace" (_: true); profiles.clerie.monitoring-server.probeTargets.blackbox-local-synapse = targetsForProbe "synapse" (_: true);