diff --git a/agent/src/collectors/disk.rs b/agent/src/collectors/disk.rs index fb87da0..d40e57f 100644 --- a/agent/src/collectors/disk.rs +++ b/agent/src/collectors/disk.rs @@ -277,14 +277,54 @@ impl DiskCollector { for line in output_str.lines() { let parts: Vec<&str> = line.split_whitespace().collect(); if parts.len() >= 2 && parts[1] == mount_point { - let device_name = parts[0].trim(); - return Ok(vec![device_name.to_string()]); + // Remove tree symbols and extract device name (e.g., "├─nvme0n1p2" -> "nvme0n1p2") + let device_name = parts[0] + .trim_start_matches('├') + .trim_start_matches('└') + .trim_start_matches('─') + .trim(); + + // Extract base device name (e.g., "nvme0n1p2" -> "nvme0n1") + if let Some(base_device) = Self::extract_base_device(device_name) { + return Ok(vec![base_device]); + } } } Ok(Vec::new()) } + /// Extract base device name from partition (e.g., "nvme0n1p2" -> "nvme0n1", "sda1" -> "sda") + fn extract_base_device(device_name: &str) -> Option { + // Handle NVMe devices (nvme0n1p1 -> nvme0n1) + if device_name.starts_with("nvme") { + if let Some(p_pos) = device_name.find('p') { + return Some(device_name[..p_pos].to_string()); + } + } + + // Handle traditional devices (sda1 -> sda) + if device_name.len() > 1 { + let chars: Vec = device_name.chars().collect(); + let mut end_idx = chars.len(); + + // Find where the device name ends and partition number begins + for (i, &c) in chars.iter().enumerate().rev() { + if !c.is_ascii_digit() { + end_idx = i + 1; + break; + } + } + + if end_idx > 0 && end_idx < chars.len() { + return Some(chars[..end_idx].iter().collect()); + } + } + + // If no partition detected, return as-is + Some(device_name.to_string()) + } + /// Get directory size using du command (efficient for single directory) fn get_directory_size(&self, path: &str) -> Result { let output = Command::new("du")