Fix service metrics not showing - remove cache check

The service_status_cache from discovery only has active_state with
all detailed metrics set to None. During collection, get_service_status()
was returning cached data instead of fetching fresh systemctl show data.

Now always fetch fresh data to populate memory_bytes, restart_count,
and uptime_seconds properly.
This commit is contained in:
Christoffer Martinsson 2025-11-28 23:15:51 +01:00
parent 5deb8cf8d8
commit 28cfd5758f
2 changed files with 7 additions and 11 deletions

6
Cargo.lock generated
View File

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

View File

@ -353,16 +353,12 @@ impl SystemdCollector {
Ok((services, status_cache))
}
/// Get service status from cache (if available) or fallback to systemctl
/// Get service status with detailed metrics from systemctl
fn get_service_status(&self, service: &str) -> Result<ServiceStatusInfo> {
// Try to get status from cache first
if let Ok(state) = self.state.read() {
if let Some(cached_info) = state.service_status_cache.get(service) {
return Ok(cached_info.clone());
}
}
// Always fetch fresh data to get detailed metrics (memory, restarts, uptime)
// Note: Cache in service_status_cache only has basic active_state from discovery,
// with all detailed metrics set to None. We need fresh systemctl show data.
// Fallback to systemctl if not in cache (with 2 second timeout)
let output = Command::new("timeout")
.args(&[
"2",