From 9dd18e2cdc6ebafd8f0a27d513d54fe9fefa0067 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Mon, 11 Jan 2021 17:44:23 +0000 Subject: [PATCH] ops/nixos/lib/common: add nixos_running_system/nixos_booted_system node metrics --- ops/nixos/lib/common.nix | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/ops/nixos/lib/common.nix b/ops/nixos/lib/common.nix index 43b79c56ae..1fbcbf4330 100644 --- a/ops/nixos/lib/common.nix +++ b/ops/nixos/lib/common.nix @@ -149,7 +149,26 @@ in services.prometheus.exporters.node = { enable = true; - enabledCollectors = [ "systemd" ]; + enabledCollectors = [ "systemd" "textfile" ]; + extraFlags = [ + "--collector.textfile.directory=/run/prometheus-textfile-exports" + ]; }; + system.activationScripts.node-exporter = { + 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 + ''; + }; + 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 + ''; + + system.nixos.tags = lib.mkBefore [ + depot.version + ]; }; }