1
0

modules/nixfiles: Add metric for last update check

This commit is contained in:
clerie 2023-12-10 19:51:21 +01:00
parent 671f5925c1
commit cb585b9bd5
2 changed files with 12 additions and 1 deletions

View File

@ -25,7 +25,7 @@ in
serviceConfig = {
Type = "oneshot";
ExecStart = pkgs.nixfiles-system-upgrade + "/bin/nixfiles-system-upgrade --no-confirm${optionalString cfg.allowReboot " --allow-reboot"}";
ExecStart = pkgs.nixfiles-system-upgrade + "/bin/nixfiles-system-upgrade --no-confirm${optionalString cfg.allowReboot " --allow-reboot"}${optionalString (config.clerie.monitoring.enable) " --node-exporter-metrics-path /var/lib/prometheus-node-exporter/textfiles/nixfiles-system-upgrade.prom"}";
};
};
systemd.timers.nixfiles-system-auto-upgrade = {

View File

@ -4,6 +4,7 @@ set -euo pipefail
ALLOW_REBOOT=
NO_CONFIRM=
NODE_EXPORTER_METRICS_PATH=
while [[ $# -gt 0 ]]; do
case $1 in
@ -15,6 +16,11 @@ while [[ $# -gt 0 ]]; do
NO_CONFIRM=1
shift
;;
--node-exporter-metrics-path)
NODE_EXPORTER_METRICS_PATH=$2
shift
shift
;;
*)
echo "Unknown option $1"
exit 1
@ -47,6 +53,11 @@ nix-env -p "/nix/var/nix/profiles/system" --set "${STORE_PATH}"
echo "Set as boot target"
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
if [[ -n "$NODE_EXPORTER_METRICS_PATH" ]]; then
echo "Write monitoring check data"
echo "nixfiles_system_upgrade_last_check $(date +%s)" > "$NODE_EXPORTER_METRICS_PATH"
fi
BOOTED_SYSTEM_KERNEL="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})"
ACTIVATING_SYSTEM_KERNEL="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"