From 23eda90726a0e47bfdb4b77dc8f00d5dd857af87 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Tue, 27 Jul 2021 21:06:17 +0000 Subject: [PATCH] ops/nixos/lib/common: add the running system hash to the exported metrics --- ops/nixos/lib/common.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ops/nixos/lib/common.nix b/ops/nixos/lib/common.nix index fe69ead189..ae5c78c1dd 100644 --- a/ops/nixos/lib/common.nix +++ b/ops/nixos/lib/common.nix @@ -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 [