diff --git a/agent/src/cached_collector.rs b/agent/src/cached_collector.rs index 540f10c..80bbc8b 100644 --- a/agent/src/cached_collector.rs +++ b/agent/src/cached_collector.rs @@ -55,6 +55,11 @@ impl CachedCollector { self.cache.needs_refresh(&self.cache_key, &self.inner.agent_type()).await } + /// Get the cache key for this collector + pub fn cache_key(&self) -> &str { + &self.cache_key + } + /// Perform actual collection, bypassing cache pub async fn collect_fresh(&self) -> Result { let start = std::time::Instant::now(); diff --git a/agent/src/smart_agent.rs b/agent/src/smart_agent.rs index 2bfef18..3d76c3c 100644 --- a/agent/src/smart_agent.rs +++ b/agent/src/smart_agent.rs @@ -72,7 +72,7 @@ impl SmartAgent { let cached = CachedCollector::with_smart_interval( Box::new(smart_collector), Arc::clone(&cache), - format!("{}_smart", hostname), + "SmartCollector".to_string(), ); cached_collectors.push(cached); info!("SMART monitoring: {:?} (15min intervals)", valid_devices); @@ -85,7 +85,7 @@ impl SmartAgent { let cached = CachedCollector::with_smart_interval( Box::new(system_collector), Arc::clone(&cache), - format!("{}_system", hostname), + "SystemCollector".to_string(), ); cached_collectors.push(cached); info!("System monitoring: CPU, memory, temperature, C-states (5s intervals)"); @@ -101,7 +101,7 @@ impl SmartAgent { let cached = CachedCollector::with_smart_interval( Box::new(service_collector), Arc::clone(&cache), - format!("{}_services", hostname), + "ServiceCollector".to_string(), ); cached_collectors.push(cached); info!("Service monitoring: {:?} (5min intervals)", service_list); @@ -114,7 +114,7 @@ impl SmartAgent { let cached = CachedCollector::with_smart_interval( Box::new(backup_collector), Arc::clone(&cache), - format!("{}_backup", hostname), + "BackupCollector".to_string(), ); cached_collectors.push(cached); info!("Backup monitoring: repo={:?}, service={} (15min intervals)", restic_repo, backup_service); @@ -246,7 +246,7 @@ impl SmartAgent { } } else { // Use cached data - if let Some(cached_output) = self.cache.get(&format!("{}_{}", self.hostname, collector.name())).await { + if let Some(cached_output) = self.cache.get(collector.cache_key()).await { if let Err(e) = self.send_metrics(&cached_output.agent_type, &cached_output.data).await { error!("Failed to send cached metrics for {}: {}", collector.name(), e); }