ops/nixos/lib/common: add the running system hash to the exported metrics

This commit is contained in:
Luke Granger-Brown 2021-07-27 21:06:17 +00:00
parent 25372154af
commit 23eda90726

View file

@ -193,13 +193,19 @@ in
text = ''
test -d /run/prometheus-textfile-exports || mkdir /run/prometheus-textfile-exports
my_version_string="$(cat "$systemConfig/nixos-version")"
echo "nixos_running_system{version=\"$my_version_string\"} 1" > /run/prometheus-textfile-exports/running_system.prom
my_hash_string="$(readlink -f "$systemConfig" | grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')"
echo "nixos_running_system{version=\"$my_version_string\", hash=\"$my_hash_string\"} 1" > /run/prometheus-textfile-exports/running_system.prom
my_version_string="$(cat "/run/booted-system/nixos-version")"
my_hash_string="$(readlink -f "/run/booted-system" | grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')"
echo "nixos_booted_system{version=\"$my_version_string\", hash=\"$my_hash_string\"} 1" > /run/prometheus-textfile-exports/booted_system.prom
'';
};
boot.postBootCommands = lib.mkAfter ''
test -d /run/prometheus-textfile-exports || mkdir /run/prometheus-textfile-exports
my_version_string="$(cat "/run/booted-system/nixos-version")"
echo "nixos_booted_system{version=\"$my_version_string\"} 1" > /run/prometheus-textfile-exports/booted_system.prom
my_hash_string="$(readlink -f "/run/booted-system" | grep -Eo '\b[0-9a-df-np-sv-z]{32}\b')"
echo "nixos_booted_system{version=\"$my_version_string\", hash=\"$my_hash_string\"} 1" > /run/prometheus-textfile-exports/booted_system.prom
'';
system.nixos.tags = lib.mkBefore [