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 + ]; }; }