Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d5ce36ee18 | |||
| 4f80701671 | |||
| 267654fda4 | |||
| dc1105eefe |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.154"
|
version = "0.1.158"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.154"
|
version = "0.1.158"
|
||||||
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.154"
|
version = "0.1.158"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.154"
|
version = "0.1.158"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -457,17 +457,21 @@ impl DiskCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serial number parsing
|
// Serial number parsing (both SATA and NVMe)
|
||||||
if line.starts_with("Serial Number:") {
|
if line.contains("Serial Number:") {
|
||||||
if let Some(serial_part) = line.split("Serial Number:").nth(1) {
|
if let Some(serial_part) = line.split("Serial Number:").nth(1) {
|
||||||
if let Some(serial_str) = serial_part.split_whitespace().next() {
|
let serial_str = serial_part.trim();
|
||||||
serial_number = Some(serial_str.to_string());
|
if !serial_str.is_empty() {
|
||||||
|
// Take first whitespace-separated token
|
||||||
|
if let Some(serial) = serial_str.split_whitespace().next() {
|
||||||
|
serial_number = Some(serial.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temperature parsing for different drive types
|
// Temperature parsing for different drive types
|
||||||
if line.contains("Temperature_Celsius") || line.contains("Airflow_Temperature_Cel") {
|
if line.contains("Temperature_Celsius") || line.contains("Airflow_Temperature_Cel") || line.contains("Temperature_Case") {
|
||||||
// Traditional SATA drives: attribute table format
|
// Traditional SATA drives: attribute table format
|
||||||
if let Some(temp_str) = line.split_whitespace().nth(9) {
|
if let Some(temp_str) = line.split_whitespace().nth(9) {
|
||||||
if let Ok(temp) = temp_str.parse::<f32>() {
|
if let Ok(temp) = temp_str.parse::<f32>() {
|
||||||
@@ -485,7 +489,15 @@ impl DiskCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wear level parsing for SSDs
|
// Wear level parsing for SSDs
|
||||||
if line.contains("Wear_Leveling_Count") || line.contains("SSD_Life_Left") {
|
if line.contains("Media_Wearout_Indicator") {
|
||||||
|
// Media_Wearout_Indicator stores remaining life % in column 3 (VALUE)
|
||||||
|
if let Some(wear_str) = line.split_whitespace().nth(3) {
|
||||||
|
if let Ok(remaining) = wear_str.parse::<f32>() {
|
||||||
|
wear_percent = Some(100.0 - remaining); // Convert remaining life to wear
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if line.contains("Wear_Leveling_Count") || line.contains("SSD_Life_Left") {
|
||||||
|
// Other wear attributes store value in column 9 (RAW_VALUE)
|
||||||
if let Some(wear_str) = line.split_whitespace().nth(9) {
|
if let Some(wear_str) = line.split_whitespace().nth(9) {
|
||||||
if let Ok(wear) = wear_str.parse::<f32>() {
|
if let Ok(wear) = wear_str.parse::<f32>() {
|
||||||
wear_percent = Some(100.0 - wear); // Convert remaining life to wear
|
wear_percent = Some(100.0 - wear); // Convert remaining life to wear
|
||||||
@@ -534,6 +546,7 @@ impl DiskCollector {
|
|||||||
|
|
||||||
agent_data.system.storage.drives.push(DriveData {
|
agent_data.system.storage.drives.push(DriveData {
|
||||||
name: drive.name.clone(),
|
name: drive.name.clone(),
|
||||||
|
serial_number: smart.and_then(|s| s.serial_number.clone()),
|
||||||
health: smart.map(|s| s.health.clone()).unwrap_or_else(|| drive.health.clone()),
|
health: smart.map(|s| s.health.clone()).unwrap_or_else(|| drive.health.clone()),
|
||||||
temperature_celsius: smart.and_then(|s| s.temperature_celsius),
|
temperature_celsius: smart.and_then(|s| s.temperature_celsius),
|
||||||
wear_percent: smart.and_then(|s| s.wear_percent),
|
wear_percent: smart.and_then(|s| s.wear_percent),
|
||||||
@@ -634,10 +647,19 @@ impl DiskCollector {
|
|||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
// Calculate overall pool health string and status
|
// Calculate overall pool health string and status
|
||||||
let (pool_health, health_status) = match (failed_data, failed_parity) {
|
// SnapRAID logic: can tolerate up to N parity drive failures (where N = number of parity drives)
|
||||||
(0, 0) => ("healthy".to_string(), cm_dashboard_shared::Status::Ok),
|
// If data drives fail AND we've lost parity protection, that's critical
|
||||||
(1, 0) | (0, 1) => ("degraded".to_string(), cm_dashboard_shared::Status::Warning),
|
let (pool_health, health_status) = if failed_data == 0 && failed_parity == 0 {
|
||||||
_ => ("critical".to_string(), cm_dashboard_shared::Status::Critical),
|
("healthy".to_string(), cm_dashboard_shared::Status::Ok)
|
||||||
|
} else if failed_data == 0 && failed_parity > 0 {
|
||||||
|
// Parity failed but no data loss - degraded (reduced protection)
|
||||||
|
("degraded".to_string(), cm_dashboard_shared::Status::Warning)
|
||||||
|
} else if failed_data == 1 && failed_parity == 0 {
|
||||||
|
// One data drive failed, parity intact - degraded (recoverable)
|
||||||
|
("degraded".to_string(), cm_dashboard_shared::Status::Warning)
|
||||||
|
} else {
|
||||||
|
// Multiple data drives failed OR data+parity failed = data loss risk
|
||||||
|
("critical".to_string(), cm_dashboard_shared::Status::Critical)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate pool usage status using config thresholds
|
// Calculate pool usage status using config thresholds
|
||||||
|
|||||||
@@ -83,14 +83,25 @@ impl NixOSCollector {
|
|||||||
std::env::var("CM_DASHBOARD_VERSION").unwrap_or_else(|_| "unknown".to_string())
|
std::env::var("CM_DASHBOARD_VERSION").unwrap_or_else(|_| "unknown".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get NixOS system generation (build) information
|
/// Get NixOS system generation (build) information from git commit
|
||||||
async fn get_nixos_generation(&self) -> Option<String> {
|
async fn get_nixos_generation(&self) -> Option<String> {
|
||||||
match Command::new("nixos-version").output() {
|
// Try to read git commit hash from file written during rebuild
|
||||||
Ok(output) => {
|
let commit_file = "/var/lib/cm-dashboard/git-commit";
|
||||||
let version_str = String::from_utf8_lossy(&output.stdout);
|
match fs::read_to_string(commit_file) {
|
||||||
Some(version_str.trim().to_string())
|
Ok(content) => {
|
||||||
|
let commit_hash = content.trim();
|
||||||
|
if commit_hash.len() >= 7 {
|
||||||
|
debug!("Found git commit hash: {}", commit_hash);
|
||||||
|
Some(commit_hash.to_string())
|
||||||
|
} else {
|
||||||
|
debug!("Git commit hash too short: {}", commit_hash);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
debug!("Failed to read git commit file {}: {}", commit_file, e);
|
||||||
|
None
|
||||||
}
|
}
|
||||||
Err(_) => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.154"
|
version = "0.1.158"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -239,8 +239,11 @@ impl SystemWidget {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Add drive info
|
// Add drive info
|
||||||
|
let display_name = drive.serial_number.as_ref()
|
||||||
|
.map(|s| truncate_serial(s))
|
||||||
|
.unwrap_or(drive.name.clone());
|
||||||
let storage_drive = StorageDrive {
|
let storage_drive = StorageDrive {
|
||||||
name: drive.name.clone(),
|
name: display_name,
|
||||||
temperature: drive.temperature_celsius,
|
temperature: drive.temperature_celsius,
|
||||||
wear_percent: drive.wear_percent,
|
wear_percent: drive.wear_percent,
|
||||||
status: Status::Ok,
|
status: Status::Ok,
|
||||||
@@ -311,7 +314,9 @@ impl SystemWidget {
|
|||||||
Status::Unknown
|
Status::Unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
let display_name = drive.serial_number.clone().unwrap_or(drive.name.clone());
|
let display_name = drive.serial_number.as_ref()
|
||||||
|
.map(|s| truncate_serial(s))
|
||||||
|
.unwrap_or(drive.name.clone());
|
||||||
let storage_drive = StorageDrive {
|
let storage_drive = StorageDrive {
|
||||||
name: display_name,
|
name: display_name,
|
||||||
temperature: drive.temperature_celsius,
|
temperature: drive.temperature_celsius,
|
||||||
@@ -334,7 +339,9 @@ impl SystemWidget {
|
|||||||
Status::Unknown
|
Status::Unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
let display_name = drive.serial_number.clone().unwrap_or(drive.name.clone());
|
let display_name = drive.serial_number.as_ref()
|
||||||
|
.map(|s| truncate_serial(s))
|
||||||
|
.unwrap_or(drive.name.clone());
|
||||||
let storage_drive = StorageDrive {
|
let storage_drive = StorageDrive {
|
||||||
name: display_name,
|
name: display_name,
|
||||||
temperature: drive.temperature_celsius,
|
temperature: drive.temperature_celsius,
|
||||||
@@ -361,12 +368,8 @@ impl SystemWidget {
|
|||||||
// Pool header line with type and health
|
// Pool header line with type and health
|
||||||
let pool_label = if pool.pool_type == "drive" {
|
let pool_label = if pool.pool_type == "drive" {
|
||||||
// For physical drives, show the drive name with temperature and wear percentage if available
|
// For physical drives, show the drive name with temperature and wear percentage if available
|
||||||
// Look for any drive with temp/wear data (physical drives may have drives named after the pool)
|
// Physical drives only have one drive entry
|
||||||
let drive_info = pool.drives.iter()
|
if let Some(drive) = pool.drives.first() {
|
||||||
.find(|d| d.name == pool.name)
|
|
||||||
.or_else(|| pool.drives.first());
|
|
||||||
|
|
||||||
if let Some(drive) = drive_info {
|
|
||||||
let mut drive_details = Vec::new();
|
let mut drive_details = Vec::new();
|
||||||
if let Some(temp) = drive.temperature {
|
if let Some(temp) = drive.temperature {
|
||||||
drive_details.push(format!("T: {}°C", temp as i32));
|
drive_details.push(format!("T: {}°C", temp as i32));
|
||||||
@@ -376,16 +379,16 @@ impl SystemWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !drive_details.is_empty() {
|
if !drive_details.is_empty() {
|
||||||
format!("{} {}", pool.name, drive_details.join(" "))
|
format!("{} {}", drive.name, drive_details.join(" "))
|
||||||
} else {
|
} else {
|
||||||
pool.name.clone()
|
drive.name.clone()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pool.name.clone()
|
pool.name.clone()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// For mergerfs pools, show pool name with format like "mergerfs (2+1):"
|
// For mergerfs pools, show pool type with mount point
|
||||||
format!("{}:", pool.pool_type)
|
format!("mergerfs {}:", pool.mount_point)
|
||||||
};
|
};
|
||||||
|
|
||||||
let pool_spans = StatusIcons::create_status_spans(pool.status.clone(), &pool_label);
|
let pool_spans = StatusIcons::create_status_spans(pool.status.clone(), &pool_label);
|
||||||
@@ -424,7 +427,7 @@ impl SystemWidget {
|
|||||||
// └─ Mount: /srv/media
|
// └─ Mount: /srv/media
|
||||||
|
|
||||||
// Pool total usage
|
// Pool total usage
|
||||||
let total_text = format!("Total: {:.0}% {:.1}GB/{:.1}GB",
|
let total_text = format!("{:.0}% {:.1}GB/{:.1}GB",
|
||||||
pool.usage_percent.unwrap_or(0.0),
|
pool.usage_percent.unwrap_or(0.0),
|
||||||
pool.used_gb.unwrap_or(0.0),
|
pool.used_gb.unwrap_or(0.0),
|
||||||
pool.total_gb.unwrap_or(0.0)
|
pool.total_gb.unwrap_or(0.0)
|
||||||
@@ -435,22 +438,37 @@ impl SystemWidget {
|
|||||||
total_spans.extend(StatusIcons::create_status_spans(Status::Ok, &total_text));
|
total_spans.extend(StatusIcons::create_status_spans(Status::Ok, &total_text));
|
||||||
lines.push(Line::from(total_spans));
|
lines.push(Line::from(total_spans));
|
||||||
|
|
||||||
// Data Disks section
|
// Data drives - at same level as parity
|
||||||
if !pool.data_drives.is_empty() {
|
let has_parity = !pool.parity_drives.is_empty();
|
||||||
lines.push(Line::from(vec![
|
for (i, drive) in pool.data_drives.iter().enumerate() {
|
||||||
Span::styled(" ├─ ", Typography::tree()),
|
let is_last_data = i == pool.data_drives.len() - 1;
|
||||||
Span::styled("Data Disks:", Typography::secondary())
|
let mut drive_details = Vec::new();
|
||||||
]));
|
if let Some(temp) = drive.temperature {
|
||||||
for (i, drive) in pool.data_drives.iter().enumerate() {
|
drive_details.push(format!("T: {}°C", temp as i32));
|
||||||
let is_last = i == pool.data_drives.len() - 1;
|
|
||||||
let tree_symbol = if is_last { " │ └─ " } else { " │ ├─ " };
|
|
||||||
render_mergerfs_drive(drive, tree_symbol, &mut lines);
|
|
||||||
}
|
}
|
||||||
|
if let Some(wear) = drive.wear_percent {
|
||||||
|
drive_details.push(format!("W: {}%", wear as i32));
|
||||||
|
}
|
||||||
|
|
||||||
|
let drive_text = if !drive_details.is_empty() {
|
||||||
|
format!("Data_{}: {} {}", i + 1, drive.name, drive_details.join(" "))
|
||||||
|
} else {
|
||||||
|
format!("Data_{}: {}", i + 1, drive.name)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Last data drive uses └─ if there's no parity, otherwise ├─
|
||||||
|
let tree_symbol = if is_last_data && !has_parity { " └─ " } else { " ├─ " };
|
||||||
|
let mut data_spans = vec![
|
||||||
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
|
];
|
||||||
|
data_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
|
||||||
|
lines.push(Line::from(data_spans));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parity section
|
// Parity drives - last item(s)
|
||||||
if !pool.parity_drives.is_empty() {
|
if !pool.parity_drives.is_empty() {
|
||||||
for drive in &pool.parity_drives {
|
for (i, drive) in pool.parity_drives.iter().enumerate() {
|
||||||
|
let is_last = i == pool.parity_drives.len() - 1;
|
||||||
let mut drive_details = Vec::new();
|
let mut drive_details = Vec::new();
|
||||||
if let Some(temp) = drive.temperature {
|
if let Some(temp) = drive.temperature {
|
||||||
drive_details.push(format!("T: {}°C", temp as i32));
|
drive_details.push(format!("T: {}°C", temp as i32));
|
||||||
@@ -460,25 +478,19 @@ impl SystemWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let drive_text = if !drive_details.is_empty() {
|
let drive_text = if !drive_details.is_empty() {
|
||||||
format!("{} {}", drive.name, drive_details.join(" "))
|
format!("Parity: {} {}", drive.name, drive_details.join(" "))
|
||||||
} else {
|
} else {
|
||||||
drive.name.clone()
|
format!("Parity: {}", drive.name)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
let mut parity_spans = vec![
|
let mut parity_spans = vec![
|
||||||
Span::styled(" ├─ ", Typography::tree()),
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
Span::styled("Parity: ", Typography::secondary()),
|
|
||||||
];
|
];
|
||||||
parity_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
|
parity_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
|
||||||
lines.push(Line::from(parity_spans));
|
lines.push(Line::from(parity_spans));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mount point
|
|
||||||
lines.push(Line::from(vec![
|
|
||||||
Span::styled(" └─ Mount: ", Typography::tree()),
|
|
||||||
Span::styled(&pool.mount_point, Typography::secondary())
|
|
||||||
]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,6 +498,16 @@ impl SystemWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Truncate serial number to last 8 characters
|
||||||
|
fn truncate_serial(serial: &str) -> String {
|
||||||
|
let len = serial.len();
|
||||||
|
if len > 8 {
|
||||||
|
serial[len - 8..].to_string()
|
||||||
|
} else {
|
||||||
|
serial.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper function to render a drive in a MergerFS pool
|
/// Helper function to render a drive in a MergerFS pool
|
||||||
fn render_mergerfs_drive<'a>(drive: &StorageDrive, tree_symbol: &'a str, lines: &mut Vec<Line<'a>>) {
|
fn render_mergerfs_drive<'a>(drive: &StorageDrive, tree_symbol: &'a str, lines: &mut Vec<Line<'a>>) {
|
||||||
let mut drive_details = Vec::new();
|
let mut drive_details = Vec::new();
|
||||||
@@ -542,6 +564,7 @@ impl SystemWidget {
|
|||||||
|
|
||||||
// First line: serial number with temperature and wear
|
// First line: serial number with temperature and wear
|
||||||
if let Some(serial) = &self.backup_disk_serial {
|
if let Some(serial) = &self.backup_disk_serial {
|
||||||
|
let truncated_serial = truncate_serial(serial);
|
||||||
let mut details = Vec::new();
|
let mut details = Vec::new();
|
||||||
if let Some(temp) = self.backup_disk_temperature {
|
if let Some(temp) = self.backup_disk_temperature {
|
||||||
details.push(format!("T: {}°C", temp as i32));
|
details.push(format!("T: {}°C", temp as i32));
|
||||||
@@ -551,9 +574,9 @@ impl SystemWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let disk_text = if !details.is_empty() {
|
let disk_text = if !details.is_empty() {
|
||||||
format!("{} {}", serial, details.join(" "))
|
format!("{} {}", truncated_serial, details.join(" "))
|
||||||
} else {
|
} else {
|
||||||
serial.clone()
|
truncated_serial
|
||||||
};
|
};
|
||||||
|
|
||||||
let backup_status = match self.backup_status.as_str() {
|
let backup_status = match self.backup_status.as_str() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.154"
|
version = "0.1.158"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ pub struct StorageData {
|
|||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct DriveData {
|
pub struct DriveData {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub serial_number: Option<String>,
|
||||||
pub health: String,
|
pub health: String,
|
||||||
pub temperature_celsius: Option<f32>,
|
pub temperature_celsius: Option<f32>,
|
||||||
pub wear_percent: Option<f32>,
|
pub wear_percent: Option<f32>,
|
||||||
|
|||||||
Reference in New Issue
Block a user