This commit is contained in:
Christoffer Martinsson 2025-10-12 19:02:50 +02:00
parent c8c91bdfec
commit 0b1d3ae0ad

View File

@ -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<SmartDeviceData, CollectorError> {
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