Add NVMe device type flag for SMART data collection
All checks were successful
Build and Release / build-and-release (push) Successful in 1m19s
All checks were successful
Build and Release / build-and-release (push) Successful in 1m19s
This commit is contained in:
@@ -385,7 +385,6 @@ impl DiskCollector {
|
||||
|
||||
/// Get SMART data for drives
|
||||
async fn get_smart_data_for_drives(&self, physical_drives: &[PhysicalDrive], mergerfs_pools: &[MergerfsPool]) -> HashMap<String, SmartData> {
|
||||
use tracing::info;
|
||||
let mut smart_data = HashMap::new();
|
||||
|
||||
// Collect all drive names
|
||||
@@ -402,48 +401,36 @@ impl DiskCollector {
|
||||
}
|
||||
}
|
||||
|
||||
info!("Collecting SMART data for {} drives", all_drives.len());
|
||||
|
||||
// Get SMART data for each drive
|
||||
for drive_name in &all_drives {
|
||||
match self.get_smart_data(drive_name).await {
|
||||
Ok(data) => {
|
||||
info!("SMART data collected for {}: serial={:?}, temp={:?}, health={}",
|
||||
drive_name, data.serial_number, data.temperature_celsius, data.health);
|
||||
smart_data.insert(drive_name.clone(), data);
|
||||
}
|
||||
Err(e) => {
|
||||
info!("Failed to get SMART data for {}: {:?}", drive_name, e);
|
||||
}
|
||||
for drive_name in all_drives {
|
||||
if let Ok(data) = self.get_smart_data(&drive_name).await {
|
||||
smart_data.insert(drive_name, data);
|
||||
}
|
||||
}
|
||||
|
||||
info!("SMART data collection complete: {}/{} drives successful", smart_data.len(), all_drives.len());
|
||||
smart_data
|
||||
}
|
||||
|
||||
/// Get SMART data for a single drive
|
||||
async fn get_smart_data(&self, drive_name: &str) -> Result<SmartData, CollectorError> {
|
||||
use tracing::info;
|
||||
|
||||
// Use direct smartctl (no sudo) - service has CAP_SYS_RAWIO capability
|
||||
let output = Command::new("smartctl")
|
||||
.args(&["-a", &format!("/dev/{}", drive_name)])
|
||||
.output()
|
||||
// For NVMe drives, specify device type explicitly
|
||||
let mut cmd = Command::new("smartctl");
|
||||
if drive_name.starts_with("nvme") {
|
||||
cmd.args(&["-d", "nvme", "-a", &format!("/dev/{}", drive_name)]);
|
||||
} else {
|
||||
cmd.args(&["-a", &format!("/dev/{}", drive_name)]);
|
||||
}
|
||||
|
||||
let output = cmd.output()
|
||||
.map_err(|e| CollectorError::SystemRead {
|
||||
path: format!("SMART data for {}", drive_name),
|
||||
error: e.to_string(),
|
||||
})?;
|
||||
|
||||
let output_str = String::from_utf8_lossy(&output.stdout);
|
||||
let error_str = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
// Debug logging for SMART command results
|
||||
debug!("SMART output for {}: status={}, stdout_len={}, stderr={}",
|
||||
drive_name, output.status, output_str.len(), error_str);
|
||||
|
||||
if !output.status.success() {
|
||||
info!("SMART command failed for {}, status={}, stderr={}", drive_name, output.status, error_str);
|
||||
// Return unknown data rather than failing completely
|
||||
return Ok(SmartData {
|
||||
health: "UNKNOWN".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user