services/prometheus: collect ping metrics in enthalpy network

This commit is contained in:
Lu Wang 2024-12-22 23:41:00 +08:00
parent ac082d8fec
commit 71ed8b5ebb
Signed by: rebmit
SSH key fingerprint: SHA256:3px8QV1zEerIrEWHaqtH5rR9kjetyRST5EipOPrd+bU
9 changed files with 63 additions and 0 deletions

View file

@ -10,6 +10,7 @@
++ (with profiles; [ ++ (with profiles; [
services.caddy services.caddy
services.prometheus.node-exporter services.prometheus.node-exporter
services.prometheus.ping-exporter
]) ])
++ (mylib.path.scanPaths ./. "default.nix"); ++ (mylib.path.scanPaths ./. "default.nix");

View file

@ -10,6 +10,7 @@
++ (with profiles; [ ++ (with profiles; [
services.caddy services.caddy
services.prometheus.node-exporter services.prometheus.node-exporter
services.prometheus.ping-exporter
]) ])
++ (mylib.path.scanPaths ./. "default.nix"); ++ (mylib.path.scanPaths ./. "default.nix");

View file

@ -12,6 +12,7 @@
services.knot.secondary services.knot.secondary
services.ntfy services.ntfy
services.prometheus.node-exporter services.prometheus.node-exporter
services.prometheus.ping-exporter
services.prometheus.server services.prometheus.server
]) ])
++ (mylib.path.scanPaths ./. "default.nix"); ++ (mylib.path.scanPaths ./. "default.nix");

View file

@ -11,6 +11,7 @@
services.caddy services.caddy
services.knot.primary services.knot.primary
services.prometheus.node-exporter services.prometheus.node-exporter
services.prometheus.ping-exporter
]) ])
++ (mylib.path.scanPaths ./. "default.nix"); ++ (mylib.path.scanPaths ./. "default.nix");

View file

@ -11,6 +11,7 @@
services.caddy services.caddy
services.knot.secondary services.knot.secondary
services.prometheus.node-exporter services.prometheus.node-exporter
services.prometheus.ping-exporter
]) ])
++ (mylib.path.scanPaths ./. "default.nix"); ++ (mylib.path.scanPaths ./. "default.nix");

View file

@ -20,6 +20,7 @@
services.miniflux services.miniflux
services.postgresql services.postgresql
services.prometheus.node-exporter services.prometheus.node-exporter
services.prometheus.ping-exporter
services.well-known services.well-known
]) ])
++ (mylib.path.scanPaths ./. "default.nix"); ++ (mylib.path.scanPaths ./. "default.nix");

View file

@ -34,6 +34,7 @@ in
prometheus-alertmanager = 4061; prometheus-alertmanager = 4061;
prometheus-node-exporter = 4070; prometheus-node-exporter = 4070;
prometheus-blackbox-exporter = 4071; prometheus-blackbox-exporter = 4071;
prometheus-ping-exporter = 4072;
# public ports # public ports
enthalpy-wireguard-reimu-aston = 13101; enthalpy-wireguard-reimu-aston = 13101;

View file

@ -0,0 +1,46 @@
{
config,
lib,
...
}:
let
common = import ../../../../zones/common.nix;
enthalpyHosts = lib.filterAttrs (_name: value: value.enthalpy_node_address != null) common.hosts;
targets = lib.mapAttrsToList (name: _value: "${name}.enta.rebmit.link") enthalpyHosts;
in
{
services.prometheus.exporters.ping = {
enable = true;
listenAddress = "127.0.0.1";
port = config.networking.ports.prometheus-ping-exporter;
telemetryPath = "/ping";
settings = {
inherit targets;
};
};
systemd.services.prometheus-ping-exporter = {
inherit (config.networking.netns.enthalpy) serviceConfig;
after = [ "netns-enthalpy.service" ];
partOf = [ "netns-enthalpy.service" ];
wantedBy = [ "netns-enthalpy.service" ];
};
networking.netns.default.forwardPorts = lib.singleton {
protocol = "tcp";
netns = "enthalpy";
source = "127.0.0.1:${toString config.networking.ports.prometheus-ping-exporter}";
target = "127.0.0.1:${toString config.networking.ports.prometheus-ping-exporter}";
};
services.caddy.virtualHosts."${config.networking.fqdn}" = {
extraConfig = with config.services.prometheus.exporters.ping; ''
route /ping {
basic_auth {
prometheus {$PROM_PASSWD}
}
reverse_proxy ${listenAddress}:${toString port}
}
'';
};
}

View file

@ -74,6 +74,16 @@ in
}; };
static_configs = [ { inherit targets; } ]; static_configs = [ { inherit targets; } ];
} }
{
job_name = "ping";
scheme = "https";
metrics_path = "/ping";
basic_auth = {
username = "prometheus";
password_file = config.sops.secrets."prometheus/password".path;
};
static_configs = [ { inherit targets; } ];
}
{ {
job_name = "dns"; job_name = "dns";
scheme = "http"; scheme = "http";