diff --git a/agent/src/collectors/smart.rs b/agent/src/collectors/smart.rs index a5bd955..3db0dfb 100644 --- a/agent/src/collectors/smart.rs +++ b/agent/src/collectors/smart.rs @@ -28,6 +28,23 @@ impl SmartCollector { } } + async fn is_device_mounted(&self, device: &str) -> bool { + // Check if device is mounted by looking in /proc/mounts + if let Ok(mounts) = tokio::fs::read_to_string("/proc/mounts").await { + for line in mounts.lines() { + let parts: Vec<&str> = line.split_whitespace().collect(); + if parts.len() >= 2 { + // Check if this mount point references our device + // Handle both /dev/nvme0n1p1 style and /dev/sda1 style + if parts[0].starts_with(&format!("/dev/{}", device)) { + return true; + } + } + } + } + false + } + async fn get_smart_data(&self, device: &str) -> Result { let timeout_duration = Duration::from_millis(self.timeout_ms); @@ -274,6 +291,11 @@ impl Collector for SmartCollector { // Collect data from all configured devices for device in &self.devices { + // Skip unmounted devices + if !self.is_device_mounted(device).await { + continue; + } + match self.get_smart_data(device).await { Ok(mut drive_data) => { // Try to get capacity and usage for this drive