2024-07-31 06:27:03 +00:00
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.custom.prometheus;
|
|
|
|
in
|
|
|
|
{
|
2024-07-31 07:37:42 +00:00
|
|
|
config = lib.mkIf (cfg.enable && cfg.exporters.caddy.enable) {
|
2024-07-31 06:27:03 +00:00
|
|
|
services.caddy.globalConfig = lib.mkIf cfg.exporters.caddy.enable ''
|
|
|
|
servers {
|
|
|
|
metrics
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
services.prometheus.scrapeConfigs = [
|
2024-07-31 07:37:42 +00:00
|
|
|
{
|
2024-07-31 06:27:03 +00:00
|
|
|
job_name = "caddy";
|
|
|
|
static_configs = [
|
|
|
|
{ targets = [ "127.0.0.1:2019" ]; }
|
|
|
|
];
|
2024-07-31 07:37:42 +00:00
|
|
|
}
|
2024-07-31 06:27:03 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
custom.prometheus.ruleModules = [
|
2024-07-31 07:37:42 +00:00
|
|
|
{
|
2024-07-31 06:27:03 +00:00
|
|
|
name = "caddy_alerts";
|
|
|
|
rules = [
|
|
|
|
{
|
|
|
|
alert = "UpstreamHealthy";
|
|
|
|
expr = "caddy_reverse_proxy_upstreams_healthy != 1";
|
|
|
|
for = "5m";
|
|
|
|
labels = { severity = "critical"; };
|
|
|
|
annotations = { summary = "Upstream {{ $labels.unstream }} not healthy"; };
|
|
|
|
}
|
|
|
|
];
|
2024-07-31 07:37:42 +00:00
|
|
|
}
|
2024-07-31 06:27:03 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|