feat: implement website alerting plan with Blackbox Exporter and VictoriaMetrics integration
This commit is contained in:
72
hosts/web-arm/modules/grafana/alerting/websites/default.nix
Normal file
72
hosts/web-arm/modules/grafana/alerting/websites/default.nix
Normal file
@@ -0,0 +1,72 @@
|
||||
{ lib, pkgs, config, ... }:
|
||||
|
||||
let
|
||||
nginxVHosts = config.services.nginx.virtualHosts or {};
|
||||
allDomains = lib.attrNames nginxVHosts;
|
||||
httpsDomains = lib.map (d: "https://${d}") allDomains;
|
||||
websiteAlertRules = lib.map (target:
|
||||
let
|
||||
domain = lib.replaceStrings ["://" "." "-" "/" ] ["-" "-" "_" "_"] target + "-down-alert";
|
||||
uid = builtins.hashString "sha1" domain;
|
||||
in {
|
||||
uid = uid;
|
||||
title = "Website " + target + " Down";
|
||||
condition = "C";
|
||||
|
||||
data = [
|
||||
{
|
||||
refId = "A";
|
||||
relativeTimeRange = { from = 300; to = 0; };
|
||||
datasourceUid = "vm-datasource-uid";
|
||||
model = {
|
||||
editorMode = "code";
|
||||
expr = "probe_success{target=\"" + target + "\"} OR on() vector(0)";
|
||||
hide = false;
|
||||
intervalMs = 1000;
|
||||
legendFormat = target;
|
||||
maxDataPoints = 43200;
|
||||
range = true;
|
||||
refId = "A";
|
||||
};
|
||||
}
|
||||
{
|
||||
refId = "B";
|
||||
datasourceUid = "__expr__";
|
||||
model = {
|
||||
type = "reduce";
|
||||
expression = "A";
|
||||
reducer = "last";
|
||||
};
|
||||
}
|
||||
{
|
||||
refId = "C";
|
||||
datasourceUid = "__expr__";
|
||||
model = {
|
||||
type = "math";
|
||||
expression = "$B < 1";
|
||||
};
|
||||
}
|
||||
];
|
||||
noDataState = "Alerting";
|
||||
execErrState = "Alerting";
|
||||
for = "5m";
|
||||
annotations = {
|
||||
description = "Website " + target + " is unreachable.";
|
||||
summary = "Website Down";
|
||||
};
|
||||
labels = {
|
||||
severity = "critical";
|
||||
website_url = target;
|
||||
};
|
||||
}
|
||||
) httpsDomains;
|
||||
in {
|
||||
services.grafana.provision.alerting.rules.settings.groups = [
|
||||
{
|
||||
name = "Website Alerts";
|
||||
folder = "Websites";
|
||||
interval = "1m";
|
||||
rules = websiteAlertRules;
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -31,6 +31,7 @@ in
|
||||
# Individual alert files removed, now handled by alerting/system/default.nix
|
||||
./alerting/system/default.nix # Added: Imports the consolidated system alerts module
|
||||
./alerting/service/default.nix # Added: Imports the new service alerts module
|
||||
./alerting/websites/default.nix # Added: Imports the new websites alerts module
|
||||
# ... other rule files can be added here ...
|
||||
./datasources/victoriametrics.nix
|
||||
./datasources/loki.nix # Add Loki datasource
|
||||
|
||||
Reference in New Issue
Block a user