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:
parent
5deb8cf8d8
commit
28cfd5758f
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.205"
|
version = "0.1.206"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.205"
|
version = "0.1.206"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@ -324,7 +324,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.205"
|
version = "0.1.206"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@ -353,16 +353,12 @@ impl SystemdCollector {
|
|||||||
Ok((services, status_cache))
|
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> {
|
fn get_service_status(&self, service: &str) -> Result<ServiceStatusInfo> {
|
||||||
// Try to get status from cache first
|
// Always fetch fresh data to get detailed metrics (memory, restarts, uptime)
|
||||||
if let Ok(state) = self.state.read() {
|
// Note: Cache in service_status_cache only has basic active_state from discovery,
|
||||||
if let Some(cached_info) = state.service_status_cache.get(service) {
|
// with all detailed metrics set to None. We need fresh systemctl show data.
|
||||||
return Ok(cached_info.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to systemctl if not in cache (with 2 second timeout)
|
|
||||||
let output = Command::new("timeout")
|
let output = Command::new("timeout")
|
||||||
.args(&[
|
.args(&[
|
||||||
"2",
|
"2",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user