Add kernel changed metric
This commit is contained in:
parent
f3ea6ee9d5
commit
7e019abec4
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -450,7 +450,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nixos-exporter"
|
name = "nixos-exporter"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "nixos-exporter"
|
name = "nixos-exporter"
|
||||||
version = "0.4.0"
|
version = "0.5.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
in {
|
in {
|
||||||
nixos-exporter = pkgs.rustPlatform.buildRustPackage rec {
|
nixos-exporter = pkgs.rustPlatform.buildRustPackage rec {
|
||||||
pname = "nixos-exporter";
|
pname = "nixos-exporter";
|
||||||
version = "0.4.0";
|
version = "0.5.0";
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
|
22
src/main.rs
22
src/main.rs
@ -174,14 +174,14 @@ async fn main() {
|
|||||||
|
|
||||||
async fn metrics() -> Result<(StatusCode, impl IntoResponse), (StatusCode, impl IntoResponse)> {
|
async fn metrics() -> Result<(StatusCode, impl IntoResponse), (StatusCode, impl IntoResponse)> {
|
||||||
let nix_store_paths = HashMap::from([
|
let nix_store_paths = HashMap::from([
|
||||||
("current_system", NixStorePath::from_str_symlink("/run/current-system")
|
("current_system", NixStorePath::from_str_symlink("/run/current-system")
|
||||||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?),
|
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?),
|
||||||
("current_system_kernel", NixStorePath::from_str_symlink("/run/current-system/kernel")
|
("current_system_kernel", NixStorePath::from_str_symlink("/run/current-system/kernel")
|
||||||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?),
|
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?),
|
||||||
("booted_system", NixStorePath::from_str_symlink("/run/booted-system")
|
("booted_system", NixStorePath::from_str_symlink("/run/booted-system")
|
||||||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?),
|
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?),
|
||||||
("booted_system_kernel", NixStorePath::from_str_symlink("/run/booted-system/kernel")
|
("booted_system_kernel", NixStorePath::from_str_symlink("/run/booted-system/kernel")
|
||||||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?),
|
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err))?),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let mut out = String::new();
|
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());
|
.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((
|
return Ok((
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
out,
|
out,
|
||||||
|
Loading…
Reference in New Issue
Block a user