|
|
|
|
@@ -164,10 +164,9 @@ impl SystemWidget {
|
|
|
|
|
for metric in metrics {
|
|
|
|
|
if metric.name.starts_with("disk_") {
|
|
|
|
|
if let Some(pool_name) = self.extract_pool_name(&metric.name) {
|
|
|
|
|
let mount_point = self.get_mount_point_for_pool(&pool_name);
|
|
|
|
|
let pool = pools.entry(pool_name.clone()).or_insert_with(|| StoragePool {
|
|
|
|
|
name: pool_name.clone(),
|
|
|
|
|
mount_point: mount_point.clone(),
|
|
|
|
|
mount_point: self.get_mount_point_for_pool(&pool_name), // Default fallback
|
|
|
|
|
pool_type: "single".to_string(), // Default, will be updated
|
|
|
|
|
pool_health: None,
|
|
|
|
|
drives: Vec::new(),
|
|
|
|
|
@@ -196,6 +195,10 @@ impl SystemWidget {
|
|
|
|
|
if let MetricValue::Float(total) = metric.value {
|
|
|
|
|
pool.total_gb = Some(total);
|
|
|
|
|
}
|
|
|
|
|
} else if metric.name.contains("_mount_point") {
|
|
|
|
|
if let MetricValue::String(mount_point) = &metric.value {
|
|
|
|
|
pool.mount_point = mount_point.clone();
|
|
|
|
|
}
|
|
|
|
|
} else if metric.name.contains("_pool_type") {
|
|
|
|
|
if let MetricValue::String(pool_type) = &metric.value {
|
|
|
|
|
pool.pool_type = pool_type.clone();
|
|
|
|
|
@@ -343,35 +346,52 @@ impl SystemWidget {
|
|
|
|
|
|
|
|
|
|
/// Extract pool name from disk metric name
|
|
|
|
|
fn extract_pool_name(&self, metric_name: &str) -> Option<String> {
|
|
|
|
|
// Pattern: disk_{pool_name}_{drive_name}_{metric_type}
|
|
|
|
|
// Pattern: disk_{pool_name}_{various suffixes}
|
|
|
|
|
// Since pool_name can contain underscores, work backwards from known metric suffixes
|
|
|
|
|
if metric_name.starts_with("disk_") {
|
|
|
|
|
// First try drive-specific metrics that have device names
|
|
|
|
|
if let Some(suffix_pos) = metric_name.rfind("_temperature")
|
|
|
|
|
// Handle filesystem metrics: disk_{pool}_fs_{filesystem}_{metric}
|
|
|
|
|
if metric_name.contains("_fs_") {
|
|
|
|
|
if let Some(fs_pos) = metric_name.find("_fs_") {
|
|
|
|
|
return Some(metric_name[5..fs_pos].to_string()); // Skip "disk_", extract pool name before "_fs_"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Handle pool-level metrics (usage_percent, used_gb, total_gb, mount_point, pool_type, pool_health)
|
|
|
|
|
else if let Some(suffix_pos) = metric_name.rfind("_usage_percent")
|
|
|
|
|
.or_else(|| metric_name.rfind("_used_gb"))
|
|
|
|
|
.or_else(|| metric_name.rfind("_total_gb"))
|
|
|
|
|
.or_else(|| metric_name.rfind("_available_gb"))
|
|
|
|
|
.or_else(|| metric_name.rfind("_mount_point"))
|
|
|
|
|
.or_else(|| metric_name.rfind("_pool_type"))
|
|
|
|
|
.or_else(|| metric_name.rfind("_pool_health")) {
|
|
|
|
|
return Some(metric_name[5..suffix_pos].to_string()); // Skip "disk_"
|
|
|
|
|
}
|
|
|
|
|
// Handle drive-specific metrics: disk_{pool}_{drive_role}_{metric} (for mergerfs) or disk_{pool}_{drive}_{metric} (for physical drives)
|
|
|
|
|
else if let Some(suffix_pos) = metric_name.rfind("_temperature")
|
|
|
|
|
.or_else(|| metric_name.rfind("_wear_percent"))
|
|
|
|
|
.or_else(|| metric_name.rfind("_health")) {
|
|
|
|
|
// Find the second-to-last underscore to get pool name
|
|
|
|
|
// For mergerfs pools, metrics look like: disk_srv_media_data_0_temperature or disk_srv_media_parity_0_temperature
|
|
|
|
|
// We need to extract just "srv_media" as the pool name
|
|
|
|
|
let before_suffix = &metric_name[..suffix_pos];
|
|
|
|
|
|
|
|
|
|
// Check if this looks like a mergerfs drive metric (contains data_ or parity_)
|
|
|
|
|
if before_suffix.contains("_data_") {
|
|
|
|
|
if let Some(data_pos) = before_suffix.find("_data_") {
|
|
|
|
|
return Some(metric_name[5..data_pos].to_string()); // Extract pool name before "_data_"
|
|
|
|
|
}
|
|
|
|
|
} else if before_suffix.contains("_parity_") {
|
|
|
|
|
if let Some(parity_pos) = before_suffix.find("_parity_") {
|
|
|
|
|
return Some(metric_name[5..parity_pos].to_string()); // Extract pool name before "_parity_"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fallback for physical drive metrics: find the second-to-last underscore
|
|
|
|
|
if let Some(drive_start) = before_suffix.rfind('_') {
|
|
|
|
|
if drive_start > 5 {
|
|
|
|
|
return Some(metric_name[5..drive_start].to_string()); // Skip "disk_"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Handle filesystem metrics: disk_{pool}_fs_{filesystem}_{metric}
|
|
|
|
|
else if metric_name.contains("_fs_") {
|
|
|
|
|
if let Some(fs_pos) = metric_name.find("_fs_") {
|
|
|
|
|
return Some(metric_name[5..fs_pos].to_string()); // Skip "disk_", extract pool name before "_fs_"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// For pool-level metrics (usage_percent, used_gb, total_gb), take everything before the metric suffix
|
|
|
|
|
else if let Some(suffix_pos) = metric_name.rfind("_usage_percent")
|
|
|
|
|
.or_else(|| metric_name.rfind("_used_gb"))
|
|
|
|
|
.or_else(|| metric_name.rfind("_total_gb"))
|
|
|
|
|
.or_else(|| metric_name.rfind("_available_gb")) {
|
|
|
|
|
return Some(metric_name[5..suffix_pos].to_string()); // Skip "disk_"
|
|
|
|
|
}
|
|
|
|
|
// Fallback to old behavior for unknown patterns
|
|
|
|
|
// Fallback: extract first component after disk_ prefix
|
|
|
|
|
else if let Some(captures) = metric_name.strip_prefix("disk_") {
|
|
|
|
|
if let Some(pos) = captures.find('_') {
|
|
|
|
|
return Some(captures[..pos].to_string());
|
|
|
|
|
@@ -409,13 +429,22 @@ impl SystemWidget {
|
|
|
|
|
/// Extract drive name from disk metric name
|
|
|
|
|
fn extract_drive_name(&self, metric_name: &str) -> Option<String> {
|
|
|
|
|
// Pattern: disk_{pool_name}_{drive_name}_{metric_type}
|
|
|
|
|
// For mergerfs: disk_{pool_name}_{data|parity}_{index}_{metric_type}
|
|
|
|
|
// Since pool_name can contain underscores, work backwards from known metric suffixes
|
|
|
|
|
if metric_name.starts_with("disk_") {
|
|
|
|
|
if let Some(suffix_pos) = metric_name.rfind("_temperature")
|
|
|
|
|
.or_else(|| metric_name.rfind("_wear_percent"))
|
|
|
|
|
.or_else(|| metric_name.rfind("_health")) {
|
|
|
|
|
// Find the second-to-last underscore to get the drive name
|
|
|
|
|
let before_suffix = &metric_name[..suffix_pos];
|
|
|
|
|
|
|
|
|
|
// For mergerfs drive metrics: extract the role_index part (e.g., "data_0", "parity_1")
|
|
|
|
|
if before_suffix.contains("_data_") || before_suffix.contains("_parity_") {
|
|
|
|
|
if let Some(role_start) = before_suffix.rfind("_data_").or_else(|| before_suffix.rfind("_parity_")) {
|
|
|
|
|
return Some(before_suffix[role_start + 1..].to_string()); // e.g., "data_0" or "parity_1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fallback for physical drive metrics: get the last component
|
|
|
|
|
if let Some(drive_start) = before_suffix.rfind('_') {
|
|
|
|
|
return Some(before_suffix[drive_start + 1..].to_string());
|
|
|
|
|
}
|
|
|
|
|
@@ -483,7 +512,7 @@ impl SystemWidget {
|
|
|
|
|
lines.push(Line::from(usage_spans));
|
|
|
|
|
|
|
|
|
|
// Drive lines with enhanced grouping
|
|
|
|
|
if pool.pool_type != "single" && pool.drives.len() > 1 {
|
|
|
|
|
if pool.pool_type.contains("mergerfs") && pool.drives.len() > 1 {
|
|
|
|
|
// Group drives by type for mergerfs pools
|
|
|
|
|
let (data_drives, parity_drives): (Vec<_>, Vec<_>) = pool.drives.iter().enumerate()
|
|
|
|
|
.partition(|(_, drive)| {
|
|
|
|
|
@@ -492,7 +521,7 @@ impl SystemWidget {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Show data drives
|
|
|
|
|
if !data_drives.is_empty() && pool.pool_type.contains("mergerfs") {
|
|
|
|
|
if !data_drives.is_empty() {
|
|
|
|
|
lines.push(Line::from(vec![
|
|
|
|
|
Span::raw(" "),
|
|
|
|
|
Span::styled("├─ ", Typography::tree()),
|
|
|
|
|
@@ -510,7 +539,7 @@ impl SystemWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Show parity drives
|
|
|
|
|
if !parity_drives.is_empty() && pool.pool_type.contains("mergerfs") {
|
|
|
|
|
if !parity_drives.is_empty() {
|
|
|
|
|
lines.push(Line::from(vec![
|
|
|
|
|
Span::raw(" "),
|
|
|
|
|
Span::styled("└─ ", Typography::tree()),
|
|
|
|
|
@@ -525,13 +554,13 @@ impl SystemWidget {
|
|
|
|
|
self.render_drive_line(&mut lines, drive, " ├─");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Regular drive listing for non-mergerfs pools
|
|
|
|
|
for (i, drive) in pool.drives.iter().enumerate() {
|
|
|
|
|
let is_last = i == pool.drives.len() - 1;
|
|
|
|
|
let tree_symbol = if is_last { "└─" } else { "├─" };
|
|
|
|
|
self.render_drive_line(&mut lines, drive, tree_symbol);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if pool.pool_type != "single" && pool.drives.len() > 1 {
|
|
|
|
|
// Regular drive listing for non-mergerfs multi-drive pools
|
|
|
|
|
for (i, drive) in pool.drives.iter().enumerate() {
|
|
|
|
|
let is_last = i == pool.drives.len() - 1;
|
|
|
|
|
let tree_symbol = if is_last { "└─" } else { "├─" };
|
|
|
|
|
self.render_drive_line(&mut lines, drive, tree_symbol);
|
|
|
|
|
}
|
|
|
|
|
} else if pool.pool_type.starts_with("drive (") {
|
|
|
|
|
// Physical drive pools: show drive info + filesystem children
|
|
|
|
|
|