diff --git a/agent/Cargo.toml b/agent/Cargo.toml index f313bf7..2a00d9a 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.41" +version = "0.1.42" edition = "2021" [dependencies] diff --git a/agent/src/collectors/nixos.rs b/agent/src/collectors/nixos.rs index 2948cd1..8abcf4f 100644 --- a/agent/src/collectors/nixos.rs +++ b/agent/src/collectors/nixos.rs @@ -37,6 +37,22 @@ impl NixOSCollector { } /// Get configuration hash from deployed nix store system + /// Get git commit hash from rebuild process + fn get_git_commit(&self) -> Result> { + let commit_file = "/var/lib/cm-dashboard/git-commit"; + match std::fs::read_to_string(commit_file) { + Ok(content) => { + let commit_hash = content.trim(); + if commit_hash.len() >= 7 { + Ok(commit_hash.to_string()) + } else { + Err("Git commit hash too short".into()) + } + } + Err(e) => Err(format!("Failed to read git commit file: {}", e).into()) + } + } + fn get_config_hash(&self) -> Result> { // Read the symlink target of /run/current-system to get nix store path let output = Command::new("readlink") @@ -74,25 +90,25 @@ impl Collector for NixOSCollector { let mut metrics = Vec::new(); let timestamp = chrono::Utc::now().timestamp() as u64; - // Collect NixOS build information (config hash) - match self.get_config_hash() { - Ok(config_hash) => { + // Collect git commit information (shows what's actually deployed) + match self.get_git_commit() { + Ok(git_commit) => { metrics.push(Metric { name: "system_nixos_build".to_string(), - value: MetricValue::String(config_hash), + value: MetricValue::String(git_commit), unit: None, - description: Some("NixOS deployed configuration hash".to_string()), + description: Some("Git commit hash of deployed configuration".to_string()), status: Status::Ok, timestamp, }); } Err(e) => { - debug!("Failed to get config hash: {}", e); + debug!("Failed to get git commit: {}", e); metrics.push(Metric { name: "system_nixos_build".to_string(), value: MetricValue::String("unknown".to_string()), unit: None, - description: Some("NixOS config hash (failed to detect)".to_string()), + description: Some("Git commit hash (failed to detect)".to_string()), status: Status::Unknown, timestamp, }); diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 1365cd3..3c8fdf0 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.41" +version = "0.1.42" edition = "2021" [dependencies] diff --git a/dashboard/src/main.rs b/dashboard/src/main.rs index aae47c9..7093675 100644 --- a/dashboard/src/main.rs +++ b/dashboard/src/main.rs @@ -14,7 +14,7 @@ use app::Dashboard; /// Get hardcoded version fn get_version() -> &'static str { - "v0.1.41" + "v0.1.42" } /// Check if running inside tmux session diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 2907acb..48bdccd 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.41" +version = "0.1.42" edition = "2021" [dependencies]