extremist-software/modules/blackbox-exporter.nix

228 lines
5 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
blackboxConfig = pkgs.writeText "blackbox.yml" ''
modules:
http_2xx:
prober: http
timeout: 5s
http:
preferred_ip_protocol: ip4
tcp_connect:
prober: tcp
timeout: 5s
tcp:
preferred_ip_protocol: ip4
icmp:
prober: icmp
timeout: 5s
icmp:
preferred_ip_protocol: ip4
'';
blackboxAddress = "127.0.0.1:${toString config.services.prometheus.exporters.blackbox.port}";
mkBlackboxJob = name: module: interval: monitors: {
job_name = name;
scrape_interval = interval;
metrics_path = "/probe";
params.module = [ module ];
static_configs = map (
{ name, target }:
{
targets = [ target ];
labels.monitor = name;
}
) monitors;
relabel_configs = [
{
source_labels = [ "__address__" ];
target_label = "__param_target";
}
{
source_labels = [ "__param_target" ];
target_label = "instance";
}
{
target_label = "__address__";
replacement = blackboxAddress;
}
];
};
http60Monitors = [
{
name = "Website (Apex)";
target = "https://extremist.software";
}
{
name = "Extremist Software Forgejo";
target = "https://git.extremist.software";
}
{
name = "Stalwart Admin";
target = "https://mail.extremist.software";
}
{
name = "SearxNG";
target = "https://search.extremist.software";
}
{
name = "Grafana";
target = "https://status.extremist.software";
}
{
name = "ntfy";
target = "https://ntfy.extremist.software";
}
{
name = "Matrix";
target = "https://matrix.extremist.software";
}
{
name = "Noisebell";
target = "https://noisebell.extremist.software";
}
{
name = "Noisebell Discord";
target = "https://discord.noisebell.extremist.software";
}
{
name = "Noisebell RSS";
target = "https://rss.noisebell.extremist.software";
}
{
name = "Noisepics";
target = "https://noisepics.extremist.software";
}
{
name = "Noisebridge Mailing List";
target = "https://lists.noisebridge.net";
}
{
name = "Noisebridge Safespace";
target = "https://safespace.noisebridge.net";
}
{
name = "Noisebridge Library";
target = "https://library.noisebridge.net";
}
{
name = "Noisebridge Electronic Parts";
target = "https://parts.noisebridge.net";
}
{
name = "Noisebridge Auth";
target = "https://auth.noisebridge.net";
}
{
name = "Noisebridge Grafana";
target = "https://grafana.noisebridge.net";
}
{
name = "Noisebridge Prometheus";
target = "https://prometheus.noisebridge.net";
}
{
name = "jetpham.com";
target = "https://jetpham.com";
}
{
name = "m3.noisebridge.net";
target = "https://m3.noisebridge.net";
}
{
name = "m5.noisebridge.net";
target = "https://m5.noisebridge.net";
}
{
name = "m6.noisebridge.net";
target = "https://m6.noisebridge.net";
}
{
name = "m7.noisebridge.net";
target = "https://m7.noisebridge.net";
}
{
name = "Gitcafe";
target = "https://app.gitcafe.dev";
}
{
name = "Github";
target = "https://github.com/";
}
{
name = "Gitlab";
target = "https://gitlab.com";
}
{
name = "git.paperclover.net";
target = "https://git.paperclover.net/clo";
}
];
http600Monitors = [
{
name = "Noisebridge Wiki";
target = "https://www.noisebridge.net/";
}
{
name = "noisebridge.org";
target = "https://www.noisebridge.org";
}
{
name = "noisebridge.io";
target = "https://noisebridge.io";
}
];
tcp60Monitors = [
{
name = "SMTP (Standard)";
target = "extremist.software:25";
}
{
name = "SMTPS (Secure)";
target = "extremist.software:465";
}
{
name = "Submission";
target = "mail.extremist.software:587";
}
{
name = "IMAPS (Secure)";
target = "extremist.software:993";
}
{
name = "Noisebridge Mailing list SMTP";
target = "lists.noisebridge.net:25";
}
];
icmp60Monitors = [
{
name = "extremist.software ping";
target = "extremist.software";
}
];
in
{
services.prometheus.exporters.blackbox = {
enable = true;
listenAddress = "127.0.0.1";
port = 9115;
configFile = blackboxConfig;
};
services.prometheus.scrapeConfigs = lib.mkAfter [
(mkBlackboxJob "blackbox-http-60s" "http_2xx" "60s" http60Monitors)
(mkBlackboxJob "blackbox-http-600s" "http_2xx" "600s" http600Monitors)
(mkBlackboxJob "blackbox-tcp-60s" "tcp_connect" "60s" tcp60Monitors)
(mkBlackboxJob "blackbox-icmp-60s" "icmp" "60s" icmp60Monitors)
];
}