diff --git a/agent/src/collectors/systemd.rs b/agent/src/collectors/systemd.rs index 4ff4ac0..88b47b3 100644 --- a/agent/src/collectors/systemd.rs +++ b/agent/src/collectors/systemd.rs @@ -56,7 +56,13 @@ impl SystemdCollector { /// Get monitored services, discovering them if needed or cache is expired fn get_monitored_services(&self) -> Result> { - let mut state = self.state.write().unwrap(); + let mut state = match self.state.write() { + Ok(state) => state, + Err(e) => { + debug!("Failed to acquire write lock on systemd state: {}", e); + return Ok(Vec::new()); // Return empty list instead of crashing + } + }; // Check if we need to discover services let needs_discovery = match state.last_discovery_time { @@ -91,7 +97,13 @@ impl SystemdCollector { /// Get nginx site metrics, checking them if cache is expired fn get_nginx_site_metrics(&self) -> Vec { - let mut state = self.state.write().unwrap(); + let mut state = match self.state.write() { + Ok(state) => state, + Err(e) => { + debug!("Failed to acquire write lock for nginx metrics: {}", e); + return Vec::new(); // Return empty list instead of crashing + } + }; // Check if we need to refresh nginx site metrics let needs_refresh = match state.last_nginx_check_time { @@ -201,6 +213,11 @@ impl SystemdCollector { state.service_status_cache = status_cache; } + debug!("Service discovery completed: found {} matching services", services.len()); + if services.is_empty() { + debug!("No services found matching the configured filters - this is a valid state"); + } + Ok(services) }