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
This commit is contained in:
Christoffer Martinsson 2025-11-23 18:24:39 +01:00
parent 86501fd486
commit f24c4ed650
5 changed files with 25 additions and 31 deletions

6
Cargo.lock generated
View File

@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
[[package]] [[package]]
name = "cm-dashboard" name = "cm-dashboard"
version = "0.1.125" version = "0.1.126"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@ -301,7 +301,7 @@ dependencies = [
[[package]] [[package]]
name = "cm-dashboard-agent" name = "cm-dashboard-agent"
version = "0.1.125" version = "0.1.126"
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.125" version = "0.1.126"
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.125" version = "0.1.126"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

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

View File

@ -357,21 +357,20 @@ impl SystemWidget {
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_"
} }
} }
// Handle pool-level metrics (usage_percent, used_gb, total_gb, mount_point, pool_type, pool_health) // 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") // Use rfind to get the last occurrence of these suffixes
.or_else(|| metric_name.rfind("_used_gb")) let pool_suffixes = ["_usage_percent", "_used_gb", "_total_gb", "_available_gb", "_mount_point", "_pool_type", "_pool_health"];
.or_else(|| metric_name.rfind("_total_gb")) for suffix in pool_suffixes {
.or_else(|| metric_name.rfind("_available_gb")) if let Some(suffix_pos) = metric_name.rfind(suffix) {
.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_" return Some(metric_name[5..suffix_pos].to_string()); // Skip "disk_"
} }
}
// Handle drive-specific metrics: disk_{pool}_{drive}_{metric} // Handle drive-specific metrics: disk_{pool}_{drive}_{metric}
else if let Some(suffix_pos) = metric_name.rfind("_temperature") let drive_suffixes = ["_temperature", "_wear_percent", "_health"];
.or_else(|| metric_name.rfind("_wear_percent")) for suffix in drive_suffixes {
.or_else(|| metric_name.rfind("_health")) { if let Some(suffix_pos) = metric_name.rfind(suffix) {
// For both mergerfs and physical drives: disk_{pool_name}_{drive_name}_{metric}
// Extract pool name by finding the second-to-last underscore // Extract pool name by finding the second-to-last underscore
let before_suffix = &metric_name[..suffix_pos]; let before_suffix = &metric_name[..suffix_pos];
if let Some(drive_start) = before_suffix.rfind('_') { if let Some(drive_start) = before_suffix.rfind('_') {
@ -380,11 +379,6 @@ impl SystemWidget {
} }
} }
} }
// 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());
}
} }
} }
None None

View File

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