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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user