Add kernel version to statusbar
All checks were successful
Build and Release / build-and-release (push) Successful in 1m37s

This commit is contained in:
2025-12-15 16:26:54 +01:00
parent 76931f0457
commit 41a7ee660a
8 changed files with 40 additions and 15 deletions

6
Cargo.lock generated
View File

@@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
[[package]] [[package]]
name = "cm-dashboard" name = "cm-dashboard"
version = "0.1.277" version = "0.1.278"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@@ -301,7 +301,7 @@ dependencies = [
[[package]] [[package]]
name = "cm-dashboard-agent" name = "cm-dashboard-agent"
version = "0.1.277" version = "0.1.278"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@@ -325,7 +325,7 @@ dependencies = [
[[package]] [[package]]
name = "cm-dashboard-shared" name = "cm-dashboard-shared"
version = "0.1.277" version = "0.1.278"
dependencies = [ dependencies = [
"chrono", "chrono",
"serde", "serde",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard-agent" name = "cm-dashboard-agent"
version = "0.1.277" version = "0.1.278"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@@ -32,6 +32,9 @@ impl NixOSCollector {
// Set NixOS build/generation information // Set NixOS build/generation information
agent_data.build_version = self.get_nixos_generation().await; agent_data.build_version = self.get_nixos_generation().await;
// Set kernel version
agent_data.kernel_version = self.get_kernel_version().await;
// Set current timestamp // Set current timestamp
agent_data.timestamp = chrono::Utc::now().timestamp() as u64; 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()) 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<String> {
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 /// Get NixOS system generation (build) information from git commit
async fn get_nixos_generation(&self) -> Option<String> { async fn get_nixos_generation(&self) -> Option<String> {
// Try to read git commit hash from file written during rebuild // Try to read git commit hash from file written during rebuild

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard" name = "cm-dashboard"
version = "0.1.277" version = "0.1.278"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@@ -688,7 +688,7 @@ impl TuiApp {
use ratatui::widgets::Paragraph; use ratatui::widgets::Paragraph;
// Get current host info // 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) // 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) { let ip = if let Some(host_details) = self.config.hosts.get(hostname) {
host_details.get_connection_ip(hostname) host_details.get_connection_ip(hostname)
@@ -696,21 +696,22 @@ impl TuiApp {
hostname.clone() hostname.clone()
}; };
// Get build and agent versions from system widget // Get kernel, build and agent versions from system widget
let (build, agent) = if let Some(host_widgets) = self.host_widgets.get(hostname) { 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 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()); let agent = host_widgets.system_widget.get_agent_version().unwrap_or("N/A".to_string());
(build, agent) (kernel, build, agent)
} else { } 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 { } 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); let right_text = format!("Build:{} | Agent:{} ", build_version, agent_version);
// Calculate spacing to push right text to the right // Calculate spacing to push right text to the right

View File

@@ -15,6 +15,7 @@ pub struct SystemWidget {
// NixOS information // NixOS information
nixos_build: Option<String>, nixos_build: Option<String>,
agent_hash: Option<String>, agent_hash: Option<String>,
kernel_version: Option<String>,
// Network interfaces // Network interfaces
network_interfaces: Vec<cm_dashboard_shared::NetworkInterfaceData>, network_interfaces: Vec<cm_dashboard_shared::NetworkInterfaceData>,
@@ -94,6 +95,7 @@ impl SystemWidget {
Self { Self {
nixos_build: None, nixos_build: None,
agent_hash: None, agent_hash: None,
kernel_version: None,
network_interfaces: Vec::new(), network_interfaces: Vec::new(),
cpu_load_1min: None, cpu_load_1min: None,
cpu_load_5min: None, cpu_load_5min: None,
@@ -171,6 +173,11 @@ impl SystemWidget {
pub fn get_agent_version(&self) -> Option<String> { pub fn get_agent_version(&self) -> Option<String> {
self.agent_hash.clone() self.agent_hash.clone()
} }
/// Get the kernel version
pub fn get_kernel_version(&self) -> Option<String> {
self.kernel_version.clone()
}
} }
use super::Widget; use super::Widget;
@@ -181,10 +188,13 @@ impl Widget for SystemWidget {
// Extract agent version // Extract agent version
self.agent_hash = Some(agent_data.agent_version.clone()); self.agent_hash = Some(agent_data.agent_version.clone());
// Extract build version // Extract build version
self.nixos_build = agent_data.build_version.clone(); self.nixos_build = agent_data.build_version.clone();
// Extract kernel version
self.kernel_version = agent_data.kernel_version.clone();
// Extract network interfaces // Extract network interfaces
self.network_interfaces = agent_data.system.network.interfaces.clone(); self.network_interfaces = agent_data.system.network.interfaces.clone();

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard-shared" name = "cm-dashboard-shared"
version = "0.1.277" version = "0.1.278"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@@ -7,6 +7,8 @@ pub struct AgentData {
pub hostname: String, pub hostname: String,
pub agent_version: String, pub agent_version: String,
pub build_version: Option<String>, pub build_version: Option<String>,
#[serde(default)]
pub kernel_version: Option<String>,
pub timestamp: u64, pub timestamp: u64,
pub system: SystemData, pub system: SystemData,
pub services: Vec<ServiceData>, pub services: Vec<ServiceData>,
@@ -203,6 +205,7 @@ impl AgentData {
hostname, hostname,
agent_version, agent_version,
build_version: None, build_version: None,
kernel_version: None,
timestamp: chrono::Utc::now().timestamp() as u64, timestamp: chrono::Utc::now().timestamp() as u64,
system: SystemData { system: SystemData {
network: NetworkData { network: NetworkData {