ops/nixos/lib/common: add nixos_running_system/nixos_booted_system node metrics

This commit is contained in:
Luke Granger-Brown 2021-01-11 17:44:23 +00:00
parent 47c6327b4d
commit 9dd18e2cdc

View file

@ -149,7 +149,26 @@ in
services.prometheus.exporters.node = { services.prometheus.exporters.node = {
enable = true; 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
];
}; };
} }