diff --git a/Cargo.lock b/Cargo.lock index 5fdc77b..c659fb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -450,7 +450,7 @@ dependencies = [ [[package]] name = "nixos-exporter" -version = "0.4.0" +version = "0.5.0" dependencies = [ "axum", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index f8fa6d8..9299d4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nixos-exporter" -version = "0.4.0" +version = "0.5.0" edition = "2021" [dependencies] diff --git a/flake.nix b/flake.nix index a8eab61..19a0fcf 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ in { nixos-exporter = pkgs.rustPlatform.buildRustPackage rec { pname = "nixos-exporter"; - version = "0.4.0"; + version = "0.5.0"; src = ./.; diff --git a/src/main.rs b/src/main.rs index e1cae60..c5cab96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -174,14 +174,14 @@ async fn main() { async fn metrics() -> Result<(StatusCode, impl IntoResponse), (StatusCode, impl IntoResponse)> { let nix_store_paths = HashMap::from([ - ("current_system", NixStorePath::from_str_symlink("/run/current-system") - .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?), - ("current_system_kernel", NixStorePath::from_str_symlink("/run/current-system/kernel") - .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?), - ("booted_system", NixStorePath::from_str_symlink("/run/booted-system") - .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?), - ("booted_system_kernel", NixStorePath::from_str_symlink("/run/booted-system/kernel") - .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?), + ("current_system", NixStorePath::from_str_symlink("/run/current-system") + .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?), + ("current_system_kernel", NixStorePath::from_str_symlink("/run/current-system/kernel") + .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?), + ("booted_system", NixStorePath::from_str_symlink("/run/booted-system") + .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?), + ("booted_system_kernel", NixStorePath::from_str_symlink("/run/booted-system/kernel") + .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?), ]); let mut out = String::new(); @@ -190,6 +190,12 @@ async fn metrics() -> Result<(StatusCode, impl IntoResponse), (StatusCode, impl .map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?.as_str()); } + out.push_str(format!("nixos_current_system_kernel_is_booted_system_kernel{{}} {}", ( + nix_store_paths.get("current_system_kernel").ok_or_else(|| (StatusCode::INTERNAL_SERVER_ERROR, String::from("")))?.hash + == nix_store_paths.get("booted_system_kernel").ok_or_else(|| (StatusCode::INTERNAL_SERVER_ERROR, String::from("")))?.hash + ) as i32).as_str() + ); + return Ok(( StatusCode::OK, out,