diff --git a/hosts/monitoring-3/configuration.nix b/hosts/monitoring-3/configuration.nix index 1187e9c..133783e 100644 --- a/hosts/monitoring-3/configuration.nix +++ b/hosts/monitoring-3/configuration.nix @@ -10,6 +10,7 @@ ./grafana.nix ./nixos-validator.nix ./prometheus.nix + ./targets.nix ./uptimestatus.nix ]; diff --git a/hosts/monitoring-3/prometheus.nix b/hosts/monitoring-3/prometheus.nix index cd130e9..73b0eab 100644 --- a/hosts/monitoring-3/prometheus.nix +++ b/hosts/monitoring-3/prometheus.nix @@ -141,10 +141,7 @@ in { }; static_configs = [ { - targets = [ - "clerie.uber.space;infra" - "cleriewi.uber.space;infra" - ]; + targets = map (target: "${target};infra") config.profiles.clerie.monitoring-server.probeTargets.node-exporter-uberspace; } ]; relabel_configs = [ @@ -225,17 +222,7 @@ in { }; static_configs = [ { - targets = eachWithEachOther (instance: target: "${instance};${target}") blackboxMonitoringTargets [ - "clerie.de" - "tagesschau.de" - "google.com" - "achtbaan.nikhef.nl" - "fluorine.net.clerie.de" - "www.fem.tu-ilmenau.de" - "www.heise.de" - "dyon.net.entr0py.de" - "matrix.fachschaften.org" - ]; + targets = eachWithEachOther (instance: target: "${instance};${target}") blackboxMonitoringTargets config.profiles.clerie.monitoring-server.probeTargets.blackbox-icmp6; } ]; relabel_configs = [ @@ -267,18 +254,7 @@ in { }; static_configs = [ { - targets = eachWithEachOther (instance: target: "${instance};${target}") blackboxMonitoringTargets [ - "clerie.de" - "tagesschau.de" - "google.com" - "achtbaan.nikhef.nl" - "www.fem.tu-ilmenau.de" - "www.heise.de" - "matrix.bau-ha.us" - "dyon.net.entr0py.de" - "matrix.entr0py.de" - "matrix.fachschaften.org" - ]; + targets = eachWithEachOther (instance: target: "${instance};${target}") blackboxMonitoringTargets config.profiles.clerie.monitoring-server.probeTargets.blackbox-icmp4; } ]; relabel_configs = [ @@ -310,10 +286,7 @@ in { }; static_configs = [ { - targets = [ - "matrix.entr0py.de" - "matrix.fachschaften.org" - ]; + targets = config.profiles.clerie.monitoring-server.probeTargets.blackbox-local-synapse; } ]; relabel_configs = [ diff --git a/hosts/monitoring-3/targets.nix b/hosts/monitoring-3/targets.nix new file mode 100644 index 0000000..245b542 --- /dev/null +++ b/hosts/monitoring-3/targets.nix @@ -0,0 +1,7 @@ +{ ... }: + +{ + + profiles.clerie.monitoring-server.targets = builtins.fromJSON (builtins.readFile ../../monitoring/targets.json); + +} diff --git a/monitoring/targets.json b/monitoring/targets.json new file mode 100644 index 0000000..2cb4767 --- /dev/null +++ b/monitoring/targets.json @@ -0,0 +1,46 @@ +{ + "clerie.de": { + "icmp": { "enable": true }, + "http": { "enable": true } + }, + "tagesschau.de": { + "icmp": { "enable": true } + }, + "google.com": { + "icmp": { "enable": true } + }, + "achtbaan.nikhef.nl": { + "icmp": { "enable": true } + }, + "www.fem.tu-ilmenau.de": { + "icmp": { "enable": true } + }, + "www.heise.de": { + "icmp": { "enable": true } + }, + "dyon.net.entr0py.de": { + "_comment": "Backend server of matrix.entr0py.de", + "icmp": { "enable": true } + }, + "matrix.bau-ha.us": { + "icmp": { + "enable": true, + "protocols": [ "ipv4" ] + }, + "synapse": { "enable": true } + }, + "matrix.entr0py.de": { + "icmp": { "enable": true }, + "synapse": { "enable": true } + }, + "matrix.fachschaften.org": { + "icmp": { "enable": true }, + "synapse": { "enable": true } + }, + "clerie.uber.space": { + "clerie-uberspace": { "enable": true } + }, + "cleriewi.uber.space": { + "clerie-uberspace": { "enable": true } + } +} diff --git a/profiles/default.nix b/profiles/default.nix index 7d0aa97..6de6c14 100644 --- a/profiles/default.nix +++ b/profiles/default.nix @@ -14,6 +14,7 @@ ./hetzner-cloud ./hydra-build-machine ./mercury-vm + ./monitoring-server ./netcup ./network-fallback-dhcp ./router diff --git a/profiles/monitoring-server/default.nix b/profiles/monitoring-server/default.nix new file mode 100644 index 0000000..66be646 --- /dev/null +++ b/profiles/monitoring-server/default.nix @@ -0,0 +1,91 @@ +{ config, lib, ... }: + +with lib; + +let + + mkAttrsOfSubmoduleOption = description: submoduleOptions: mkOption { + type = with types; attrsOf (submodule { options = submoduleOptions; }); + default = {}; + description = description; + }; + + mkSubmoduleOption = description: submoduleOptions: mkOption { + type = types.submodule { options = submoduleOptions; }; + default = {}; + description = description; + }; + + mkProbeOption = description: submoduleOptions: mkSubmoduleOption description ({ + enable = mkEnableOption "Monitor target using this probe"; + } // submoduleOptions); + + mkProtocolsOption = mkOption { + type = with types; listOf (enum [ "ipv6" "ipv4" ]); + default = [ "ipv6" "ipv4" ]; + description = "Protocols to retrieve metrics for"; + }; + + mkTargetsListOption = mkOption { + type = with types; listOf str; + default = []; + }; + + listContains = searchValue: listToSearch: any (element: element == searchValue) listToSearch; + + targetsForProbe = probeName: condition: attrNames (filterAttrs (targetName: targetConfig: + targetConfig.${probeName}.enable == true && (condition targetConfig.${probeName}) + ) config.profiles.clerie.monitoring-server.targets); + +in { + + options.profiles.clerie.monitoring-server = { + targets = mkAttrsOfSubmoduleOption "Monitoring targets config" { + _comment = mkOption { + type = types.str; + default = ""; + }; + clerie-uberspace = mkProbeOption "This target is a uberspace host managed by clerie" {}; + http = mkProbeOption "Monitor HTTP" { + protocols = mkProtocolsOption; + }; + icmp = mkProbeOption "Monitor HTTP" { + protocols = mkProtocolsOption; + }; + synapse = mkProbeOption "Monitor Synapse Matrix server" {}; + }; + + probeTargets = mkSubmoduleOption "Target per probe" { + blackbox-http4 = mkTargetsListOption; + blackbox-http6 = mkTargetsListOption; + blackbox-icmp4 = mkTargetsListOption; + blackbox-icmp6 = mkTargetsListOption; + node-exporter-uberspace = mkTargetsListOption; + blackbox-local-synapse = mkTargetsListOption; + }; + }; + + 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) + ); + + profiles.clerie.monitoring-server.probeTargets.blackbox-icmp6 = targetsForProbe "icmp" (probeConfig: + (listContains "ipv6" probeConfig.protocols) + ); + + profiles.clerie.monitoring-server.probeTargets.node-exporter-uberspace = targetsForProbe "clerie-uberspace" (_: true); + + profiles.clerie.monitoring-server.probeTargets.blackbox-local-synapse = targetsForProbe "synapse" (_: true); + + }; +}