From 41a7ee660aa8cbc2a13cae17df80d04c16288524 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 15 Dec 2025 16:26:54 +0100 Subject: [PATCH] Add kernel version to statusbar --- Cargo.lock | 6 +++--- agent/Cargo.toml | 2 +- agent/src/collectors/nixos.rs | 11 +++++++++++ dashboard/Cargo.toml | 2 +- dashboard/src/ui/mod.rs | 17 +++++++++-------- dashboard/src/ui/widgets/system.rs | 12 +++++++++++- shared/Cargo.toml | 2 +- shared/src/agent_data.rs | 3 +++ 8 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89dae32..3fcdd9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.277" +version = "0.1.278" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.277" +version = "0.1.278" dependencies = [ "anyhow", "async-trait", @@ -325,7 +325,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.277" +version = "0.1.278" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index 5c751a7..29601f8 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.277" +version = "0.1.278" edition = "2021" [dependencies] diff --git a/agent/src/collectors/nixos.rs b/agent/src/collectors/nixos.rs index c56ce5c..00af531 100644 --- a/agent/src/collectors/nixos.rs +++ b/agent/src/collectors/nixos.rs @@ -32,6 +32,9 @@ impl NixOSCollector { // Set NixOS build/generation information agent_data.build_version = self.get_nixos_generation().await; + // Set kernel version + agent_data.kernel_version = self.get_kernel_version().await; + // Set current timestamp agent_data.timestamp = chrono::Utc::now().timestamp() as u64; @@ -80,6 +83,14 @@ impl NixOSCollector { std::env::var("CM_DASHBOARD_VERSION").unwrap_or_else(|_| "unknown".to_string()) } + /// Get kernel version from /proc/sys/kernel/osrelease + async fn get_kernel_version(&self) -> Option { + match fs::read_to_string("/proc/sys/kernel/osrelease") { + Ok(version) => Some(version.trim().to_string()), + Err(_) => None, + } + } + /// Get NixOS system generation (build) information from git commit async fn get_nixos_generation(&self) -> Option { // Try to read git commit hash from file written during rebuild diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 2b6bf62..9aba090 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.277" +version = "0.1.278" edition = "2021" [dependencies] diff --git a/dashboard/src/ui/mod.rs b/dashboard/src/ui/mod.rs index 7308421..32b1b6f 100644 --- a/dashboard/src/ui/mod.rs +++ b/dashboard/src/ui/mod.rs @@ -688,7 +688,7 @@ impl TuiApp { use ratatui::widgets::Paragraph; // Get current host info - let (hostname_str, host_ip, build_version, agent_version) = if let Some(hostname) = &self.current_host { + let (hostname_str, host_ip, kernel_version, build_version, agent_version) = if let Some(hostname) = &self.current_host { // Get the connection IP (the IP dashboard uses to connect to the agent) let ip = if let Some(host_details) = self.config.hosts.get(hostname) { host_details.get_connection_ip(hostname) @@ -696,21 +696,22 @@ impl TuiApp { hostname.clone() }; - // Get build and agent versions from system widget - let (build, agent) = if let Some(host_widgets) = self.host_widgets.get(hostname) { + // Get kernel, build and agent versions from system widget + let (kernel, build, agent) = if let Some(host_widgets) = self.host_widgets.get(hostname) { + let kernel = host_widgets.system_widget.get_kernel_version().unwrap_or("N/A".to_string()); let build = host_widgets.system_widget.get_build_version().unwrap_or("N/A".to_string()); let agent = host_widgets.system_widget.get_agent_version().unwrap_or("N/A".to_string()); - (build, agent) + (kernel, build, agent) } else { - ("N/A".to_string(), "N/A".to_string()) + ("N/A".to_string(), "N/A".to_string(), "N/A".to_string()) }; - (hostname.clone(), ip, build, agent) + (hostname.clone(), ip, kernel, build, agent) } else { - ("None".to_string(), "N/A".to_string(), "N/A".to_string(), "N/A".to_string()) + ("None".to_string(), "N/A".to_string(), "N/A".to_string(), "N/A".to_string(), "N/A".to_string()) }; - let left_text = format!(" Host: {} | {}", hostname_str, host_ip); + let left_text = format!(" Host: {} | {} | {}", hostname_str, host_ip, kernel_version); let right_text = format!("Build:{} | Agent:{} ", build_version, agent_version); // Calculate spacing to push right text to the right diff --git a/dashboard/src/ui/widgets/system.rs b/dashboard/src/ui/widgets/system.rs index fe33386..e75c4c8 100644 --- a/dashboard/src/ui/widgets/system.rs +++ b/dashboard/src/ui/widgets/system.rs @@ -15,6 +15,7 @@ pub struct SystemWidget { // NixOS information nixos_build: Option, agent_hash: Option, + kernel_version: Option, // Network interfaces network_interfaces: Vec, @@ -94,6 +95,7 @@ impl SystemWidget { Self { nixos_build: None, agent_hash: None, + kernel_version: None, network_interfaces: Vec::new(), cpu_load_1min: None, cpu_load_5min: None, @@ -171,6 +173,11 @@ impl SystemWidget { pub fn get_agent_version(&self) -> Option { self.agent_hash.clone() } + + /// Get the kernel version + pub fn get_kernel_version(&self) -> Option { + self.kernel_version.clone() + } } use super::Widget; @@ -181,10 +188,13 @@ impl Widget for SystemWidget { // Extract agent version self.agent_hash = Some(agent_data.agent_version.clone()); - + // Extract build version self.nixos_build = agent_data.build_version.clone(); + // Extract kernel version + self.kernel_version = agent_data.kernel_version.clone(); + // Extract network interfaces self.network_interfaces = agent_data.system.network.interfaces.clone(); diff --git a/shared/Cargo.toml b/shared/Cargo.toml index d176652..a1af780 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.277" +version = "0.1.278" edition = "2021" [dependencies] diff --git a/shared/src/agent_data.rs b/shared/src/agent_data.rs index 146f8d5..b543bb8 100644 --- a/shared/src/agent_data.rs +++ b/shared/src/agent_data.rs @@ -7,6 +7,8 @@ pub struct AgentData { pub hostname: String, pub agent_version: String, pub build_version: Option, + #[serde(default)] + pub kernel_version: Option, pub timestamp: u64, pub system: SystemData, pub services: Vec, @@ -203,6 +205,7 @@ impl AgentData { hostname, agent_version, build_version: None, + kernel_version: None, timestamp: chrono::Utc::now().timestamp() as u64, system: SystemData { network: NetworkData {