monitoring: no "Access files changed" alert for a deploy
All checks were successful
nixos / nixos (push) Successful in 35s
All checks were successful
nixos / nixos (push) Successful in 35s
On NixOS an activation rewrites accounts and authorized_keys whenever the configuration changes them, so every such deploy fired the alert and resolved it minutes later. Each host now records when it last activated a configuration (nixos_activation_timestamp_seconds, written on every deploy and boot), and the rule ignores changes within 20 minutes of one. A change outside a deploy, which on these hosts can only be a hand edit, still fires. Assisted-by: Claude:opus-5-5
This commit is contained in:
parent
3edcdce243
commit
23b9bede43
2 changed files with 15 additions and 1 deletions
|
|
@ -325,7 +325,8 @@ groups:
|
|||
- refId: A
|
||||
relativeTimeRange: { from: 900, to: 0 }
|
||||
datasourceUid: prometheus
|
||||
model: { refId: A, expr: "changes(security_fileset_hash[15m])", instant: true, intervalMs: 30000, maxDataPoints: 43200 }
|
||||
# Not within 20 minutes of a NixOS activation: deploys rewrite accounts and authorized_keys
|
||||
model: { refId: A, expr: "changes(security_fileset_hash[15m]) unless on(host) (time() - nixos_activation_timestamp_seconds < 1200)", instant: true, intervalMs: 30000, maxDataPoints: 43200 }
|
||||
- refId: C
|
||||
datasourceUid: __expr__
|
||||
model: { refId: C, type: threshold, expression: A, conditions: [ { evaluator: { type: gt, params: [0] } } ] }
|
||||
|
|
|
|||
|
|
@ -190,6 +190,19 @@ in
|
|||
|
||||
systemd.tmpfiles.rules = [ "d ${textfile} 0755 root root -" ];
|
||||
|
||||
# When this host last activated a NixOS configuration (deploy or
|
||||
# boot). Activations rewrite accounts and authorized_keys by design;
|
||||
# the "Access files changed" alert stays quiet around them and still
|
||||
# fires for a change outside a deploy, which here means a hand edit.
|
||||
system.activationScripts.activationMetric = {
|
||||
deps = [ ];
|
||||
text = ''
|
||||
mkdir -p ${textfile}
|
||||
printf '# HELP nixos_activation_timestamp_seconds Last NixOS activation (deploy or boot).\n# TYPE nixos_activation_timestamp_seconds gauge\nnixos_activation_timestamp_seconds %s\n' "$(${pkgs.coreutils}/bin/date +%s)" > ${textfile}/nixos.prom.tmp
|
||||
mv ${textfile}/nixos.prom.tmp ${textfile}/nixos.prom
|
||||
'';
|
||||
};
|
||||
|
||||
services.prometheus.exporters.node = {
|
||||
enable = true;
|
||||
listenAddress = ip;
|
||||
|
|
|
|||
Loading…
Reference in a new issue