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.restic.enable) {
|
2024-07-31 06:27:03 +00:00
|
|
|
services.restic.server.prometheus = true;
|
|
|
|
|
|
|
|
services.prometheus.scrapeConfigs = [
|
|
|
|
(lib.mkIf cfg.exporters.restic.enable {
|
|
|
|
job_name = "restic";
|
2024-08-25 09:45:58 +00:00
|
|
|
static_configs = [ { targets = [ config.services.restic.server.listenAddress ]; } ];
|
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 = "restic_alerts";
|
|
|
|
rules = [
|
|
|
|
{
|
|
|
|
alert = "ResticCheckFailed";
|
|
|
|
expr = "restic_check_success == 0";
|
|
|
|
for = "5m";
|
2024-08-25 09:45:58 +00:00
|
|
|
labels = {
|
|
|
|
severity = "critical";
|
|
|
|
};
|
|
|
|
annotations = {
|
|
|
|
summary = "Restic check failed (instance {{ $labels.instance }})";
|
|
|
|
description = "Restic check failed\\n VALUE = {{ $value }}\\n LABELS = {{ $labels }}";
|
|
|
|
};
|
2024-07-31 06:27:03 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
alert = "ResticOutdatedBackup";
|
|
|
|
expr = "time() - restic_backup_timestamp > 518400";
|
|
|
|
for = "0m";
|
2024-08-25 09:45:58 +00:00
|
|
|
labels = {
|
|
|
|
severity = "critical";
|
|
|
|
};
|
|
|
|
annotations = {
|
|
|
|
summary = "Restic {{ $labels.client_hostname }} / {{ $labels.client_username }} backup is outdated";
|
|
|
|
description = "Restic backup is outdated\\n VALUE = {{ $value }}\\n LABELS = {{ $labels }}";
|
|
|
|
};
|
2024-07-31 06:27:03 +00:00
|
|
|
}
|
|
|
|
];
|
2024-07-31 07:37:42 +00:00
|
|
|
}
|
2024-07-31 06:27:03 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|