Compare commits

..

16 Commits

Author SHA1 Message Date
41ded0170c Add wear percentage display and NVMe temperature collection
All checks were successful
Build and Release / build-and-release (push) Successful in 2m9s
- Display wear percentage in storage headers for single physical drives
- Remove redundant drive type indicators, show wear data instead
- Fix wear metric parsing for physical drives (underscore count issue)
- Add NVMe temperature parsing support (Temperature: format)
- Add raw metrics debugging functionality for troubleshooting
- Clean up physical drive display to remove redundant information
2025-11-23 20:29:24 +01:00
9b4191b2c3 Fix physical drive name and health status display
All checks were successful
Build and Release / build-and-release (push) Successful in 2m13s
- Display actual drive name (e.g., nvme0n1) instead of mount point for physical drives
- Fix health status parsing for physical drives to show proper status icons
- Update pool name extraction to handle disk_{drive}_health metrics correctly
- Improve storage widget rendering for physical drive identification
2025-11-23 19:25:45 +01:00
53dbb43352 Fix SnapRAID parity association using directory-based discovery
All checks were successful
Build and Release / build-and-release (push) Successful in 1m8s
- Replace blanket parity drive inclusion with smart relationship detection
- Only associate parity drives from same parent directory as data drives
- Prevent incorrect exclusion of nvme0n1 physical drives from grouping
- Maintain zero-configuration auto-discovery without hardcoded paths
2025-11-23 18:42:48 +01:00
ba03623110 Remove hardcoded pool mount point mappings for true auto-discovery
All checks were successful
Build and Release / build-and-release (push) Successful in 1m19s
- Eliminate hardcoded mappings like 'root' -> '/' and 'steampool' -> '/mnt/steampool'
- Use device names directly for physical drives
- Rely on mount_point metrics from agent for actual mount paths
- Implement zero-configuration architecture as specified in CLAUDE.md
2025-11-23 18:34:45 +01:00
f24c4ed650 Fix pool name extraction to prevent wrong physical drive naming
All checks were successful
Build and Release / build-and-release (push) Successful in 2m10s
- Remove fallback logic that could extract incorrect pool names
- Simplify pool suffix matching to use explicit arrays
- Ensure only valid metric patterns create pools
2025-11-23 18:24:39 +01:00
86501fd486 Fix display format to match CLAUDE.md specification
All checks were successful
Build and Release / build-and-release (push) Successful in 1m17s
- Use actual device names (sdb, sdc) instead of data_0, parity_0
- Fix physical drive naming to show device names instead of mount points
- Update pool name extraction to handle new device-based naming
- Ensure Drive: line shows temperature and wear data for physical drives
2025-11-23 18:13:35 +01:00
192eea6e0c Integrate SnapRAID parity drives into mergerfs pools
All checks were successful
Build and Release / build-and-release (push) Successful in 1m19s
- Add SnapRAID parity drive detection to mergerfs discovery
- Remove Pool Status health line as discussed
- Update drive display to always show wear data when available
- Include /mnt/parity drives as part of mergerfs pool structure
2025-11-23 18:05:19 +01:00
43fb838c9b Fix duplicate drive display in mergerfs pools
All checks were successful
Build and Release / build-and-release (push) Successful in 2m9s
- Restructure storage rendering logic to prevent drive duplication
- Use specific mergerfs check instead of generic multi-drive condition
- Ensure drives only appear once under organized data/parity sections
2025-11-23 17:46:09 +01:00
54483653f9 Fix mergerfs drive metric parsing for proper pool consolidation
All checks were successful
Build and Release / build-and-release (push) Successful in 2m11s
- Update extract_pool_name to handle data_/parity_ drive metrics correctly
- Fix extract_drive_name to parse mergerfs drive roles properly
- Prevent srv_media_data from being parsed as separate pool
2025-11-23 17:40:12 +01:00
e47803b705 Fix mergerfs pool consolidation and naming
All checks were successful
Build and Release / build-and-release (push) Successful in 1m18s
- Improve pool name extraction in dashboard parsing
- Use consistent mergerfs pool naming in agent
- Add mount_point metric parsing to use actual mount paths
- Fix pool consolidation to prevent duplicate entries
2025-11-23 17:35:23 +01:00
439d0d9af6 Fix mergerfs numeric reference parsing for proper pool detection
All checks were successful
Build and Release / build-and-release (push) Successful in 2m11s
Add support for numeric mergerfs references like "1:2" by mapping them
to actual mount points (/mnt/disk1, /mnt/disk2). This enables proper
mergerfs pool detection and hides individual member drives as intended.
2025-11-23 17:27:45 +01:00
2242b5ddfe Make mergerfs detection more robust to prevent discovery failures
All checks were successful
Build and Release / build-and-release (push) Successful in 2m9s
Skip mergerfs pools with numeric device references (e.g., "1:2")
instead of crashing. This allows regular drive detection to work
even when mergerfs uses non-standard mount formats.

Preserves existing functionality for standard mergerfs setups.
2025-11-23 17:19:15 +01:00
9d0f42d55c Fix filesystem usage_percent parsing and remove hardcoded status
All checks were successful
Build and Release / build-and-release (push) Successful in 1m8s
1. Add missing _fs_ filter to usage_percent parsing in dashboard
2. Fix agent to use calculated fs_status instead of hardcoded Status::Ok

This completes the disk collector auto-discovery by ensuring filesystem
usage percentages and status indicators display correctly.
2025-11-23 16:47:20 +01:00
1da7b5f6e7 Fix both pool-level and filesystem metric parsing bugs
All checks were successful
Build and Release / build-and-release (push) Successful in 1m10s
1. Prevent filesystem _fs_ metrics from overwriting pool totals
2. Fix filesystem name extraction to properly parse boot/root names

This resolves both the pool total display (showing 0.1GB instead of 220GB)
and individual filesystem display (showing —% —GB/—GB).
2025-11-23 16:29:00 +01:00
006f27f7d9 Fix lsblk parsing for filesystem discovery
All checks were successful
Build and Release / build-and-release (push) Successful in 1m9s
Remove unused debug code and fix device name parsing to properly
handle lsblk tree characters. This resolves the issue where only
/boot filesystem was discovered instead of both /boot and /.
2025-11-23 16:09:48 +01:00
07422cd0a7 Add debug logging for filesystem discovery
All checks were successful
Build and Release / build-and-release (push) Successful in 1m18s
2025-11-23 15:26:49 +01:00
8 changed files with 267 additions and 147 deletions

6
Cargo.lock generated
View File

@@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
[[package]] [[package]]
name = "cm-dashboard" name = "cm-dashboard"
version = "0.1.114" version = "0.1.129"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@@ -301,7 +301,7 @@ dependencies = [
[[package]] [[package]]
name = "cm-dashboard-agent" name = "cm-dashboard-agent"
version = "0.1.114" version = "0.1.129"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
@@ -324,7 +324,7 @@ dependencies = [
[[package]] [[package]]
name = "cm-dashboard-shared" name = "cm-dashboard-shared"
version = "0.1.114" version = "0.1.129"
dependencies = [ dependencies = [
"chrono", "chrono",
"serde", "serde",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard-agent" name = "cm-dashboard-agent"
version = "0.1.114" version = "0.1.130"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@@ -119,10 +119,7 @@ impl DiskCollector {
let parts: Vec<&str> = line.split_whitespace().collect(); let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() >= 2 { if parts.len() >= 2 {
let device_name = parts[0] let device_name = parts[0]
.trim_start_matches('├') .trim_start_matches(&['├', '└', '─', ' '][..]);
.trim_start_matches('└')
.trim_start_matches('─')
.trim();
let mount_point = parts[1]; let mount_point = parts[1];
// Skip unwanted mount points // Skip unwanted mount points
@@ -205,15 +202,34 @@ impl DiskCollector {
let (total_bytes, used_bytes) = self.get_filesystem_info(&mount_point) let (total_bytes, used_bytes) = self.get_filesystem_info(&mount_point)
.unwrap_or((0, 0)); .unwrap_or((0, 0));
// Parse member paths // Parse member paths - handle both full paths and numeric references
let member_paths: Vec<String> = device_sources let raw_paths: Vec<String> = device_sources
.split(':') .split(':')
.map(|s| s.trim().to_string()) .map(|s| s.trim().to_string())
.filter(|s| !s.is_empty()) .filter(|s| !s.is_empty())
.collect(); .collect();
// Convert numeric references to actual mount points if needed
let mut member_paths = if raw_paths.iter().any(|path| !path.starts_with('/')) {
// Handle numeric format like "1:2" by finding corresponding /mnt/disk* paths
self.resolve_numeric_mergerfs_paths(&raw_paths)?
} else {
// Already full paths
raw_paths
};
// For SnapRAID setups, include parity drives that are related to this pool's data drives
let related_parity_paths = self.discover_related_parity_drives(&member_paths)?;
member_paths.extend(related_parity_paths);
// Categorize as data vs parity drives // Categorize as data vs parity drives
let (data_drives, parity_drives) = self.categorize_pool_drives(&member_paths)?; let (data_drives, parity_drives) = match self.categorize_pool_drives(&member_paths) {
Ok(drives) => drives,
Err(e) => {
debug!("Failed to categorize drives for pool {}: {}. Skipping.", mount_point, e);
continue;
}
};
pools.push(MergerfsPool { pools.push(MergerfsPool {
mount_point, mount_point,
@@ -228,6 +244,38 @@ impl DiskCollector {
Ok(pools) Ok(pools)
} }
/// Discover parity drives that are related to the given data drives
fn discover_related_parity_drives(&self, data_drives: &[String]) -> Result<Vec<String>> {
let mount_devices = self.get_mount_devices()?;
let mut related_parity = Vec::new();
// Find parity drives that share the same parent directory as the data drives
for data_path in data_drives {
if let Some(parent_dir) = self.get_parent_directory(data_path) {
// Look for parity drives in the same parent directory
for (mount_point, _device) in &mount_devices {
if mount_point.contains("parity") && mount_point.starts_with(&parent_dir) {
if !related_parity.contains(mount_point) {
related_parity.push(mount_point.clone());
}
}
}
}
}
Ok(related_parity)
}
/// Get parent directory of a mount path (e.g., "/mnt/disk1" -> "/mnt")
fn get_parent_directory(&self, path: &str) -> Option<String> {
if let Some(last_slash) = path.rfind('/') {
if last_slash > 0 {
return Some(path[..last_slash].to_string());
}
}
None
}
/// Categorize pool member drives as data vs parity /// Categorize pool member drives as data vs parity
fn categorize_pool_drives(&self, member_paths: &[String]) -> Result<(Vec<DriveInfo>, Vec<DriveInfo>)> { fn categorize_pool_drives(&self, member_paths: &[String]) -> Result<(Vec<DriveInfo>, Vec<DriveInfo>)> {
let mut data_drives = Vec::new(); let mut data_drives = Vec::new();
@@ -289,6 +337,35 @@ impl DiskCollector {
}) })
} }
/// Resolve numeric mergerfs references like "1:2" to actual mount paths
fn resolve_numeric_mergerfs_paths(&self, numeric_refs: &[String]) -> Result<Vec<String>> {
let mut resolved_paths = Vec::new();
// Get all mount points that look like /mnt/disk* or /mnt/parity*
let mount_devices = self.get_mount_devices()?;
let mut disk_mounts: Vec<String> = mount_devices.keys()
.filter(|path| path.starts_with("/mnt/disk") || path.starts_with("/mnt/parity"))
.cloned()
.collect();
disk_mounts.sort(); // Ensure consistent ordering
for num_ref in numeric_refs {
if let Ok(index) = num_ref.parse::<usize>() {
// Convert 1-based index to 0-based
if index > 0 && index <= disk_mounts.len() {
resolved_paths.push(disk_mounts[index - 1].clone());
}
}
}
// Fallback: if we couldn't resolve, return the original paths
if resolved_paths.is_empty() {
resolved_paths = numeric_refs.to_vec();
}
Ok(resolved_paths)
}
/// Extract base device name from partition (e.g., "nvme0n1p2" -> "nvme0n1", "sda1" -> "sda") /// Extract base device name from partition (e.g., "nvme0n1p2" -> "nvme0n1", "sda1" -> "sda")
fn extract_base_device(&self, device_name: &str) -> String { fn extract_base_device(&self, device_name: &str) -> String {
// Handle NVMe devices (nvme0n1p1 -> nvme0n1) // Handle NVMe devices (nvme0n1p1 -> nvme0n1)
@@ -422,6 +499,17 @@ impl DiskCollector {
} }
} }
} }
// NVMe format: "Temperature:" (capital T)
if line.contains("Temperature:") {
if let Some(temp_part) = line.split("Temperature:").nth(1) {
if let Some(temp_str) = temp_part.split_whitespace().next() {
if let Ok(temp) = temp_str.parse::<f32>() {
return Some(temp);
}
}
}
}
// Legacy format: "temperature:" (lowercase)
if line.contains("temperature:") { if line.contains("temperature:") {
if let Some(temp_part) = line.split("temperature:").nth(1) { if let Some(temp_part) = line.split("temperature:").nth(1) {
if let Some(temp_str) = temp_part.split_whitespace().next() { if let Some(temp_str) = temp_part.split_whitespace().next() {
@@ -509,7 +597,7 @@ impl Collector for DiskCollector {
let topology = match self.discover_storage() { let topology = match self.discover_storage() {
Ok(topology) => topology, Ok(topology) => topology,
Err(e) => { Err(e) => {
debug!("Storage discovery failed: {}", e); tracing::error!("Storage discovery failed: {}", e);
return Ok(metrics); return Ok(metrics);
} }
}; };
@@ -698,7 +786,7 @@ impl DiskCollector {
value: MetricValue::Float(self.bytes_to_gb(filesystem.used_bytes)), value: MetricValue::Float(self.bytes_to_gb(filesystem.used_bytes)),
unit: Some("GB".to_string()), unit: Some("GB".to_string()),
description: Some(format!("{}: {}", filesystem.mount_point, self.bytes_to_human_readable(filesystem.used_bytes))), description: Some(format!("{}: {}", filesystem.mount_point, self.bytes_to_human_readable(filesystem.used_bytes))),
status: Status::Ok, status: fs_status.clone(),
timestamp, timestamp,
}); });
@@ -707,7 +795,7 @@ impl DiskCollector {
value: MetricValue::Float(self.bytes_to_gb(filesystem.total_bytes)), value: MetricValue::Float(self.bytes_to_gb(filesystem.total_bytes)),
unit: Some("GB".to_string()), unit: Some("GB".to_string()),
description: Some(format!("{}: {}", filesystem.mount_point, self.bytes_to_human_readable(filesystem.total_bytes))), description: Some(format!("{}: {}", filesystem.mount_point, self.bytes_to_human_readable(filesystem.total_bytes))),
status: Status::Ok, status: fs_status.clone(),
timestamp, timestamp,
}); });
@@ -740,7 +828,13 @@ impl DiskCollector {
timestamp: u64, timestamp: u64,
status_tracker: &mut StatusTracker status_tracker: &mut StatusTracker
) { ) {
let pool_name = pool.mount_point.trim_start_matches('/').replace('/', "_"); // Use consistent pool naming: extract mount point without leading slash
let pool_name = if pool.mount_point == "/" {
"root".to_string()
} else {
pool.mount_point.trim_start_matches('/').replace('/', "_")
};
if pool_name.is_empty() { if pool_name.is_empty() {
return; return;
} }
@@ -844,12 +938,12 @@ impl DiskCollector {
}); });
// Individual drive metrics // Individual drive metrics
for (i, drive) in pool.data_drives.iter().enumerate() { for drive in &pool.data_drives {
self.generate_pool_drive_metrics(metrics, &pool_name, &format!("data_{}", i), drive, timestamp, status_tracker); self.generate_pool_drive_metrics(metrics, &pool_name, &drive.device, drive, timestamp, status_tracker);
} }
for (i, drive) in pool.parity_drives.iter().enumerate() { for drive in &pool.parity_drives {
self.generate_pool_drive_metrics(metrics, &pool_name, &format!("parity_{}", i), drive, timestamp, status_tracker); self.generate_pool_drive_metrics(metrics, &pool_name, &drive.device, drive, timestamp, status_tracker);
} }
} }

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard" name = "cm-dashboard"
version = "0.1.114" version = "0.1.130"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@@ -20,12 +20,13 @@ pub struct Dashboard {
tui_app: Option<TuiApp>, tui_app: Option<TuiApp>,
terminal: Option<Terminal<CrosstermBackend<io::Stdout>>>, terminal: Option<Terminal<CrosstermBackend<io::Stdout>>>,
headless: bool, headless: bool,
raw_data: bool,
initial_commands_sent: std::collections::HashSet<String>, initial_commands_sent: std::collections::HashSet<String>,
config: DashboardConfig, config: DashboardConfig,
} }
impl Dashboard { impl Dashboard {
pub async fn new(config_path: Option<String>, headless: bool) -> Result<Self> { pub async fn new(config_path: Option<String>, headless: bool, raw_data: bool) -> Result<Self> {
info!("Initializing dashboard"); info!("Initializing dashboard");
// Load configuration - try default path if not specified // Load configuration - try default path if not specified
@@ -119,6 +120,7 @@ impl Dashboard {
tui_app, tui_app,
terminal, terminal,
headless, headless,
raw_data,
initial_commands_sent: std::collections::HashSet::new(), initial_commands_sent: std::collections::HashSet::new(),
config, config,
}) })
@@ -204,6 +206,18 @@ impl Dashboard {
.insert(metric_message.hostname.clone()); .insert(metric_message.hostname.clone());
} }
// Show raw data if requested (before processing)
if self.raw_data {
println!("RAW METRICS FROM {}: {} metrics", metric_message.hostname, metric_message.metrics.len());
for metric in &metric_message.metrics {
println!(" {}: {:?} ({:?})", metric.name, metric.value, metric.status);
if let Some(desc) = &metric.description {
println!(" └─ {}", desc);
}
}
println!("{}", "".repeat(80));
}
// Update metric store // Update metric store
self.metric_store self.metric_store
.update_metrics(&metric_message.hostname, metric_message.metrics); .update_metrics(&metric_message.hostname, metric_message.metrics);

View File

@@ -51,6 +51,10 @@ struct Cli {
/// Run in headless mode (no TUI, just logging) /// Run in headless mode (no TUI, just logging)
#[arg(long)] #[arg(long)]
headless: bool, headless: bool,
/// Show raw agent data in headless mode
#[arg(long)]
raw_data: bool,
} }
#[tokio::main] #[tokio::main]
@@ -86,7 +90,7 @@ async fn main() -> Result<()> {
} }
// Create and run dashboard // Create and run dashboard
let mut dashboard = Dashboard::new(cli.config, cli.headless).await?; let mut dashboard = Dashboard::new(cli.config, cli.headless, cli.raw_data).await?;
// Setup graceful shutdown // Setup graceful shutdown
let ctrl_c = async { let ctrl_c = async {

View File

@@ -146,14 +146,14 @@ impl SystemWidget {
self.agent_hash.as_ref() self.agent_hash.as_ref()
} }
/// Get mount point for a pool name /// Get default mount point for a pool name (fallback only - should use actual mount_point metrics)
fn get_mount_point_for_pool(&self, pool_name: &str) -> String { fn get_mount_point_for_pool(&self, pool_name: &str) -> String {
match pool_name { // For device names, use the device name directly as display name
"root" => "/".to_string(), if pool_name.starts_with("nvme") || pool_name.starts_with("sd") || pool_name.starts_with("hd") {
"steampool" => "/mnt/steampool".to_string(), pool_name.to_string()
"steampool_1" => "/steampool_1".to_string(), } else {
"steampool_2" => "/steampool_2".to_string(), // For other pools, use the pool name as-is (will be overridden by mount_point metric)
_ => format!("/{}", pool_name), // Default fallback pool_name.to_string()
} }
} }
@@ -164,10 +164,9 @@ impl SystemWidget {
for metric in metrics { for metric in metrics {
if metric.name.starts_with("disk_") { if metric.name.starts_with("disk_") {
if let Some(pool_name) = self.extract_pool_name(&metric.name) { 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 { let pool = pools.entry(pool_name.clone()).or_insert_with(|| StoragePool {
name: pool_name.clone(), 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_type: "single".to_string(), // Default, will be updated
pool_health: None, pool_health: None,
drives: Vec::new(), drives: Vec::new(),
@@ -180,19 +179,26 @@ impl SystemWidget {
}); });
// Parse different metric types // Parse different metric types
if metric.name.contains("_usage_percent") { if metric.name.contains("_usage_percent") && !metric.name.contains("_fs_") {
// Only use drive-level metrics for pool totals, not filesystem metrics
if let MetricValue::Float(usage) = metric.value { if let MetricValue::Float(usage) = metric.value {
pool.usage_percent = Some(usage); pool.usage_percent = Some(usage);
pool.status = metric.status.clone(); pool.status = metric.status.clone();
} }
} else if metric.name.contains("_used_gb") { } else if metric.name.contains("_used_gb") && !metric.name.contains("_fs_") {
// Only use drive-level metrics for pool totals, not filesystem metrics
if let MetricValue::Float(used) = metric.value { if let MetricValue::Float(used) = metric.value {
pool.used_gb = Some(used); pool.used_gb = Some(used);
} }
} else if metric.name.contains("_total_gb") { } else if metric.name.contains("_total_gb") && !metric.name.contains("_fs_") {
// Only use drive-level metrics for pool totals, not filesystem metrics
if let MetricValue::Float(total) = metric.value { if let MetricValue::Float(total) = metric.value {
pool.total_gb = Some(total); 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") { } else if metric.name.contains("_pool_type") {
if let MetricValue::String(pool_type) = &metric.value { if let MetricValue::String(pool_type) = &metric.value {
pool.pool_type = pool_type.clone(); pool.pool_type = pool_type.clone();
@@ -202,6 +208,13 @@ impl SystemWidget {
pool.pool_health = Some(health.clone()); pool.pool_health = Some(health.clone());
pool.health_status = metric.status.clone(); pool.health_status = metric.status.clone();
} }
} else if metric.name.contains("_health") && !metric.name.contains("_pool_health") {
// Handle physical drive health metrics (disk_{drive}_health)
if let MetricValue::String(health) = &metric.value {
// For physical drives, use the drive health as pool health
pool.pool_health = Some(health.clone());
pool.health_status = metric.status.clone();
}
} else if metric.name.contains("_temperature") { } else if metric.name.contains("_temperature") {
if let Some(drive_name) = self.extract_drive_name(&metric.name) { if let Some(drive_name) = self.extract_drive_name(&metric.name) {
// Find existing drive or create new one // Find existing drive or create new one
@@ -219,12 +232,16 @@ impl SystemWidget {
if let MetricValue::Float(temp) = metric.value { if let MetricValue::Float(temp) = metric.value {
drive.temperature = Some(temp); drive.temperature = Some(temp);
drive.status = metric.status.clone(); drive.status = metric.status.clone();
// For physical drives, if this is the main drive, also update pool health
if drive.name == pool.name && pool.health_status == Status::Unknown {
pool.health_status = metric.status.clone();
}
} }
} }
} }
} else if metric.name.contains("_wear_percent") { } else if metric.name.contains("_wear_percent") {
if let Some(drive_name) = self.extract_drive_name(&metric.name) { if let Some(drive_name) = self.extract_drive_name(&metric.name) {
// Find existing drive or create new one // For physical drives, ensure we create the drive object
let drive_exists = pool.drives.iter().any(|d| d.name == drive_name); let drive_exists = pool.drives.iter().any(|d| d.name == drive_name);
if !drive_exists { if !drive_exists {
pool.drives.push(StorageDrive { pool.drives.push(StorageDrive {
@@ -239,6 +256,10 @@ impl SystemWidget {
if let MetricValue::Float(wear) = metric.value { if let MetricValue::Float(wear) = metric.value {
drive.wear_percent = Some(wear); drive.wear_percent = Some(wear);
drive.status = metric.status.clone(); drive.status = metric.status.clone();
// For physical drives, if this is the main drive, also update pool health
if drive.name == pool.name && pool.health_status == Status::Unknown {
pool.health_status = metric.status.clone();
}
} }
} }
} }
@@ -340,38 +361,51 @@ impl SystemWidget {
/// Extract pool name from disk metric name /// Extract pool name from disk metric name
fn extract_pool_name(&self, metric_name: &str) -> Option<String> { 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 // Since pool_name can contain underscores, work backwards from known metric suffixes
if metric_name.starts_with("disk_") { if metric_name.starts_with("disk_") {
// First try drive-specific metrics that have device names // Handle filesystem metrics: disk_{pool}_fs_{filesystem}_{metric}
if let Some(suffix_pos) = metric_name.rfind("_temperature") if metric_name.contains("_fs_") {
.or_else(|| metric_name.rfind("_wear_percent"))
.or_else(|| metric_name.rfind("_health")) {
// Find the second-to-last underscore to get pool name
let before_suffix = &metric_name[..suffix_pos];
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_") { 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_" 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") // Handle pool-level metrics (usage_percent, used_gb, total_gb, mount_point, pool_type, pool_health)
.or_else(|| metric_name.rfind("_used_gb")) // Use rfind to get the last occurrence of these suffixes
.or_else(|| metric_name.rfind("_total_gb")) let pool_suffixes = ["_usage_percent", "_used_gb", "_total_gb", "_available_gb", "_mount_point", "_pool_type", "_pool_health"];
.or_else(|| metric_name.rfind("_available_gb")) { for suffix in pool_suffixes {
return Some(metric_name[5..suffix_pos].to_string()); // Skip "disk_" if let Some(suffix_pos) = metric_name.rfind(suffix) {
return Some(metric_name[5..suffix_pos].to_string()); // Skip "disk_"
}
} }
// Fallback to old behavior for unknown patterns
else if let Some(captures) = metric_name.strip_prefix("disk_") { // Handle physical drive metrics: disk_{drive}_health and disk_{drive}_wear_percent
if let Some(pos) = captures.find('_') { if (metric_name.ends_with("_health") && !metric_name.contains("_pool_health"))
return Some(captures[..pos].to_string()); || metric_name.ends_with("_wear_percent") {
// Count underscores to distinguish physical drive metrics (disk_{drive}_metric)
// from pool drive metrics (disk_{pool}_{drive}_metric)
let underscore_count = metric_name.matches('_').count();
// disk_nvme0n1_wear_percent has 3 underscores: disk_nvme0n1_wear_percent
if underscore_count == 3 { // disk_{drive}_wear_percent (where drive has underscores)
if let Some(suffix_pos) = metric_name.rfind("_health")
.or_else(|| metric_name.rfind("_wear_percent")) {
return Some(metric_name[5..suffix_pos].to_string()); // Skip "disk_"
}
}
}
// Handle drive-specific metrics: disk_{pool}_{drive}_{metric}
let drive_suffixes = ["_temperature", "_health"];
for suffix in drive_suffixes {
if let Some(suffix_pos) = metric_name.rfind(suffix) {
// Extract pool name by finding the second-to-last underscore
let before_suffix = &metric_name[..suffix_pos];
if let Some(drive_start) = before_suffix.rfind('_') {
if drive_start > 5 {
return Some(metric_name[5..drive_start].to_string()); // Skip "disk_"
}
}
} }
} }
} }
@@ -391,10 +425,9 @@ impl SystemWidget {
for suffix in known_suffixes { for suffix in known_suffixes {
if after_fs.ends_with(suffix) { if after_fs.ends_with(suffix) {
// Safely calculate fs_name length // Extract filesystem name by removing suffix and underscore
let suffix_with_underscore = suffix.len() + 1; if let Some(underscore_pos) = after_fs.rfind(&format!("_{}", suffix)) {
if after_fs.len() > suffix_with_underscore { let fs_name = after_fs[..underscore_pos].to_string();
let fs_name = after_fs[..after_fs.len() - suffix_with_underscore].to_string();
return (Some(fs_name), Some(suffix.to_string())); return (Some(fs_name), Some(suffix.to_string()));
} }
} }
@@ -406,16 +439,22 @@ impl SystemWidget {
/// Extract drive name from disk metric name /// Extract drive name from disk metric name
fn extract_drive_name(&self, metric_name: &str) -> Option<String> { fn extract_drive_name(&self, metric_name: &str) -> Option<String> {
// Pattern: disk_{pool_name}_{drive_name}_{metric_type} // Pattern: disk_{pool_name}_{drive_name}_{metric_type} OR disk_{drive_name}_{metric_type}
// Since pool_name can contain underscores, work backwards from known metric suffixes // Pool drives: disk_srv_media_sdb_temperature
// Physical drives: disk_nvme0n1_temperature
if metric_name.starts_with("disk_") { if metric_name.starts_with("disk_") {
if let Some(suffix_pos) = metric_name.rfind("_temperature") if let Some(suffix_pos) = metric_name.rfind("_temperature")
.or_else(|| metric_name.rfind("_wear_percent")) .or_else(|| metric_name.rfind("_wear_percent"))
.or_else(|| metric_name.rfind("_health")) { .or_else(|| metric_name.rfind("_health")) {
// Find the second-to-last underscore to get the drive name
let before_suffix = &metric_name[..suffix_pos]; let before_suffix = &metric_name[..suffix_pos];
// Extract the last component as drive name (e.g., "sdb", "sdc", "nvme0n1")
if let Some(drive_start) = before_suffix.rfind('_') { if let Some(drive_start) = before_suffix.rfind('_') {
return Some(before_suffix[drive_start + 1..].to_string()); return Some(before_suffix[drive_start + 1..].to_string());
} else {
// Handle physical drive metrics: disk_{drive}_metric (no pool)
// Extract everything after "disk_" as the drive name
return Some(before_suffix[5..].to_string()); // Skip "disk_"
} }
} }
} }
@@ -428,7 +467,18 @@ impl SystemWidget {
for pool in &self.storage_pools { for pool in &self.storage_pools {
// Pool header line with type and health // Pool header line with type and health
let pool_label = if pool.pool_type == "single" { let pool_label = if pool.pool_type.starts_with("drive (") {
// For physical drives, show the drive name with wear percentage if available
// Look for any drive with wear data (physical drives may have drives named after the pool)
let wear_opt = pool.drives.iter()
.find_map(|d| d.wear_percent);
if let Some(wear) = wear_opt {
format!("{} W: {:.0}%:", pool.name, wear)
} else {
format!("{}:", pool.name)
}
} else if pool.pool_type == "single" {
format!("{}:", pool.mount_point) format!("{}:", pool.mount_point)
} else { } else {
format!("{} ({}):", pool.mount_point, pool.pool_type) format!("{} ({}):", pool.mount_point, pool.pool_type)
@@ -439,49 +489,32 @@ impl SystemWidget {
); );
lines.push(Line::from(pool_spans)); lines.push(Line::from(pool_spans));
// Pool health line (for multi-disk pools) // Skip pool health line as discussed - removed
if pool.pool_type != "single" {
if let Some(health) = &pool.pool_health { // Total usage line (only show for multi-drive pools, skip for single physical drives)
let health_text = match health.as_str() { if !pool.pool_type.starts_with("drive (") {
"healthy" => format!("Pool Status: {} Healthy", let usage_text = match (pool.usage_percent, pool.used_gb, pool.total_gb) {
if pool.drives.len() > 1 { format!("({} drives)", pool.drives.len()) } else { String::new() }), (Some(pct), Some(used), Some(total)) => {
"degraded" => "Pool Status: ⚠ Degraded".to_string(), format!("Total: {:.0}% {:.1}GB/{:.1}GB", pct, used, total)
"critical" => "Pool Status: ✗ Critical".to_string(), }
"rebuilding" => "Pool Status: ⟳ Rebuilding".to_string(), _ => "Total: —% —GB/—GB".to_string(),
_ => format!("Pool Status: ? {}", health), };
};
let has_drives = !pool.drives.is_empty();
let mut health_spans = vec![ let has_filesystems = !pool.filesystems.is_empty();
Span::raw(" "), let has_children = has_drives || has_filesystems;
Span::styled("├─ ", Typography::tree()), let tree_symbol = if has_children { "├─" } else { "└─" };
]; let mut usage_spans = vec![
health_spans.extend(StatusIcons::create_status_spans(pool.health_status.clone(), &health_text)); Span::raw(" "),
lines.push(Line::from(health_spans)); Span::styled(tree_symbol, Typography::tree()),
} Span::raw(" "),
];
usage_spans.extend(StatusIcons::create_status_spans(pool.status.clone(), &usage_text));
lines.push(Line::from(usage_spans));
} }
// Total usage line (always show for pools)
let usage_text = match (pool.usage_percent, pool.used_gb, pool.total_gb) {
(Some(pct), Some(used), Some(total)) => {
format!("Total: {:.0}% {:.1}GB/{:.1}GB", pct, used, total)
}
_ => "Total: —% —GB/—GB".to_string(),
};
let has_drives = !pool.drives.is_empty();
let has_filesystems = !pool.filesystems.is_empty();
let has_children = has_drives || has_filesystems;
let tree_symbol = if has_children { "├─" } else { "└─" };
let mut usage_spans = vec![
Span::raw(" "),
Span::styled(tree_symbol, Typography::tree()),
Span::raw(" "),
];
usage_spans.extend(StatusIcons::create_status_spans(pool.status.clone(), &usage_text));
lines.push(Line::from(usage_spans));
// Drive lines with enhanced grouping // 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 // Group drives by type for mergerfs pools
let (data_drives, parity_drives): (Vec<_>, Vec<_>) = pool.drives.iter().enumerate() let (data_drives, parity_drives): (Vec<_>, Vec<_>) = pool.drives.iter().enumerate()
.partition(|(_, drive)| { .partition(|(_, drive)| {
@@ -490,7 +523,7 @@ impl SystemWidget {
}); });
// Show data drives // Show data drives
if !data_drives.is_empty() && pool.pool_type.contains("mergerfs") { if !data_drives.is_empty() {
lines.push(Line::from(vec![ lines.push(Line::from(vec![
Span::raw(" "), Span::raw(" "),
Span::styled("├─ ", Typography::tree()), Span::styled("├─ ", Typography::tree()),
@@ -508,7 +541,7 @@ impl SystemWidget {
} }
// Show parity drives // Show parity drives
if !parity_drives.is_empty() && pool.pool_type.contains("mergerfs") { if !parity_drives.is_empty() {
lines.push(Line::from(vec![ lines.push(Line::from(vec![
Span::raw(" "), Span::raw(" "),
Span::styled("└─ ", Typography::tree()), Span::styled("└─ ", Typography::tree()),
@@ -523,43 +556,16 @@ impl SystemWidget {
self.render_drive_line(&mut lines, drive, " ├─"); self.render_drive_line(&mut lines, drive, " ├─");
} }
} }
} else { }
// Regular drive listing for non-mergerfs pools } else if pool.pool_type != "single" && pool.drives.len() > 1 {
for (i, drive) in pool.drives.iter().enumerate() { // Regular drive listing for non-mergerfs multi-drive pools
let is_last = i == pool.drives.len() - 1; for (i, drive) in pool.drives.iter().enumerate() {
let tree_symbol = if is_last { "└─" } else { "├─" }; let is_last = i == pool.drives.len() - 1;
self.render_drive_line(&mut lines, drive, tree_symbol); let tree_symbol = if is_last { "└─" } else { "├─" };
} self.render_drive_line(&mut lines, drive, tree_symbol);
} }
} else if pool.pool_type.starts_with("drive (") { } else if pool.pool_type.starts_with("drive (") {
// Physical drive pools: show drive info + filesystem children // Physical drive pools: wear data shown in header, skip drive lines, show filesystems directly
// First show drive information
for drive in &pool.drives {
let mut drive_info = Vec::new();
if let Some(temp) = drive.temperature {
drive_info.push(format!("T: {:.0}°C", temp));
}
if let Some(wear) = drive.wear_percent {
drive_info.push(format!("W: {:.0}%", wear));
}
let drive_text = if drive_info.is_empty() {
format!("Drive: {}", drive.name)
} else {
format!("Drive: {}", drive_info.join(" "))
};
let has_filesystems = !pool.filesystems.is_empty();
let tree_symbol = if has_filesystems { "├─" } else { "└─" };
let mut drive_spans = vec![
Span::raw(" "),
Span::styled(tree_symbol, Typography::tree()),
Span::raw(" "),
];
drive_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
lines.push(Line::from(drive_spans));
}
// Then show filesystem children
for (i, filesystem) in pool.filesystems.iter().enumerate() { for (i, filesystem) in pool.filesystems.iter().enumerate() {
let is_last = i == pool.filesystems.len() - 1; let is_last = i == pool.filesystems.len() - 1;
let tree_symbol = if is_last { "└─" } else { "├─" }; let tree_symbol = if is_last { "└─" } else { "├─" };
@@ -610,10 +616,12 @@ impl SystemWidget {
if let Some(wear) = drive.wear_percent { if let Some(wear) = drive.wear_percent {
drive_info.push(format!("W: {:.0}%", wear)); drive_info.push(format!("W: {:.0}%", wear));
} }
// Always show drive name with info, or just name if no info available
let drive_text = if drive_info.is_empty() { let drive_text = if drive_info.is_empty() {
drive.name.clone() drive.name.clone()
} else { } else {
format!("{} {}", drive.name, drive_info.join(" ")) format!("{} {}", drive.name, drive_info.join(" "))
}; };
let mut drive_spans = vec![ let mut drive_spans = vec![

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "cm-dashboard-shared" name = "cm-dashboard-shared"
version = "0.1.114" version = "0.1.130"
edition = "2021" edition = "2021"
[dependencies] [dependencies]