Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77bf08a978 | |||
| 929870f8b6 | |||
| 7aae852b7b | |||
| 40f3ff66d8 | |||
| 1c1beddb55 | |||
| 620d1f10b6 | |||
| a0d571a40e | |||
| 977200fff3 | |||
| d692de5f83 | |||
| f5913dbd43 | |||
| faa30a7839 |
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.212"
|
version = "0.1.219"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.212"
|
version = "0.1.219"
|
||||||
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.212"
|
version = "0.1.219"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.213"
|
version = "0.1.220"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -142,6 +142,17 @@ impl BackupCollector {
|
|||||||
// Build service list for this disk
|
// Build service list for this disk
|
||||||
let services: Vec<String> = backup_status.services.keys().cloned().collect();
|
let services: Vec<String> = backup_status.services.keys().cloned().collect();
|
||||||
|
|
||||||
|
// Get min and max archive counts to detect inconsistencies
|
||||||
|
let archives_min: i64 = backup_status.services.values()
|
||||||
|
.map(|service| service.archive_count)
|
||||||
|
.min()
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
let archives_max: i64 = backup_status.services.values()
|
||||||
|
.map(|service| service.archive_count)
|
||||||
|
.max()
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
// Create disk data
|
// Create disk data
|
||||||
let disk_data = BackupDiskData {
|
let disk_data = BackupDiskData {
|
||||||
serial: backup_status.disk_serial_number.unwrap_or_else(|| "Unknown".to_string()),
|
serial: backup_status.disk_serial_number.unwrap_or_else(|| "Unknown".to_string()),
|
||||||
@@ -155,6 +166,8 @@ impl BackupCollector {
|
|||||||
disk_total_gb: total_gb,
|
disk_total_gb: total_gb,
|
||||||
usage_status,
|
usage_status,
|
||||||
services,
|
services,
|
||||||
|
archives_min,
|
||||||
|
archives_max,
|
||||||
};
|
};
|
||||||
|
|
||||||
disks.push(disk_data);
|
disks.push(disk_data);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use async_trait::async_trait;
|
|||||||
use cm_dashboard_shared::{AgentData, DriveData, FilesystemData, PoolData, HysteresisThresholds, Status};
|
use cm_dashboard_shared::{AgentData, DriveData, FilesystemData, PoolData, HysteresisThresholds, Status};
|
||||||
|
|
||||||
use crate::config::DiskConfig;
|
use crate::config::DiskConfig;
|
||||||
use std::process::Command;
|
use tokio::process::Command;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
@@ -763,7 +763,7 @@ impl DiskCollector {
|
|||||||
/// Get drive information for a mount path
|
/// Get drive information for a mount path
|
||||||
fn get_drive_info_for_path(&self, path: &str) -> anyhow::Result<PoolDrive> {
|
fn get_drive_info_for_path(&self, path: &str) -> anyhow::Result<PoolDrive> {
|
||||||
// Use lsblk to find the backing device with timeout
|
// Use lsblk to find the backing device with timeout
|
||||||
let output = Command::new("timeout")
|
let output = std::process::Command::new("timeout")
|
||||||
.args(&["2", "lsblk", "-rn", "-o", "NAME,MOUNTPOINT"])
|
.args(&["2", "lsblk", "-rn", "-o", "NAME,MOUNTPOINT"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to run lsblk: {}", e))?;
|
.map_err(|e| anyhow::anyhow!("Failed to run lsblk: {}", e))?;
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cm_dashboard_shared::{AgentData};
|
use cm_dashboard_shared::{AgentData};
|
||||||
use std::process::{Command, Output};
|
use std::process::Output;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::time::timeout;
|
|
||||||
|
|
||||||
pub mod backup;
|
pub mod backup;
|
||||||
pub mod cpu;
|
pub mod cpu;
|
||||||
@@ -16,16 +15,29 @@ pub mod systemd;
|
|||||||
pub use error::CollectorError;
|
pub use error::CollectorError;
|
||||||
|
|
||||||
/// Run a command with a timeout to prevent blocking
|
/// Run a command with a timeout to prevent blocking
|
||||||
pub async fn run_command_with_timeout(mut cmd: Command, timeout_secs: u64) -> std::io::Result<Output> {
|
/// Properly kills the process if timeout is exceeded
|
||||||
|
pub async fn run_command_with_timeout(mut cmd: tokio::process::Command, timeout_secs: u64) -> std::io::Result<Output> {
|
||||||
|
use tokio::time::timeout;
|
||||||
let timeout_duration = Duration::from_secs(timeout_secs);
|
let timeout_duration = Duration::from_secs(timeout_secs);
|
||||||
|
|
||||||
match timeout(timeout_duration, tokio::task::spawn_blocking(move || cmd.output())).await {
|
let child = cmd.spawn()?;
|
||||||
Ok(Ok(result)) => result,
|
let pid = child.id();
|
||||||
Ok(Err(e)) => Err(std::io::Error::new(std::io::ErrorKind::Other, e)),
|
|
||||||
Err(_) => Err(std::io::Error::new(
|
match timeout(timeout_duration, child.wait_with_output()).await {
|
||||||
std::io::ErrorKind::TimedOut,
|
Ok(result) => result,
|
||||||
format!("Command timed out after {} seconds", timeout_secs)
|
Err(_) => {
|
||||||
)),
|
// Timeout - force kill the process using system kill command
|
||||||
|
if let Some(process_id) = pid {
|
||||||
|
let _ = tokio::process::Command::new("kill")
|
||||||
|
.args(&["-9", &process_id.to_string()])
|
||||||
|
.output()
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::TimedOut,
|
||||||
|
format!("Command timed out after {} seconds", timeout_secs)
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.213"
|
version = "0.1.220"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -517,19 +517,23 @@ impl SystemWidget {
|
|||||||
let repo_spans = StatusIcons::create_status_spans(self.backup_repository_status, &repo_text);
|
let repo_spans = StatusIcons::create_status_spans(self.backup_repository_status, &repo_text);
|
||||||
lines.push(Line::from(repo_spans));
|
lines.push(Line::from(repo_spans));
|
||||||
|
|
||||||
// List all repositories
|
// List all repositories (sorted for consistent display)
|
||||||
let repo_count = self.backup_repositories.len();
|
let mut sorted_repos = self.backup_repositories.clone();
|
||||||
for (idx, repo) in self.backup_repositories.iter().enumerate() {
|
sorted_repos.sort();
|
||||||
|
let repo_count = sorted_repos.len();
|
||||||
|
for (idx, repo) in sorted_repos.iter().enumerate() {
|
||||||
let tree_char = if idx == repo_count - 1 { "└─" } else { "├─" };
|
let tree_char = if idx == repo_count - 1 { "└─" } else { "├─" };
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(format!(" {} ", tree_char), Typography::tree()),
|
Span::styled(format!(" {} ", tree_char), Typography::tree()),
|
||||||
Span::styled(repo, Typography::secondary()),
|
Span::styled(repo.clone(), Typography::secondary()),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second section: Per-disk backup information
|
// Second section: Per-disk backup information (sorted by serial for consistent display)
|
||||||
for disk in &self.backup_disks {
|
let mut sorted_disks = self.backup_disks.clone();
|
||||||
|
sorted_disks.sort_by(|a, b| a.serial.cmp(&b.serial));
|
||||||
|
for disk in &sorted_disks {
|
||||||
let truncated_serial = truncate_serial(&disk.serial);
|
let truncated_serial = truncate_serial(&disk.serial);
|
||||||
let mut details = Vec::new();
|
let mut details = Vec::new();
|
||||||
|
|
||||||
@@ -561,9 +565,16 @@ impl SystemWidget {
|
|||||||
lines.push(Line::from(time_spans));
|
lines.push(Line::from(time_spans));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show usage with status
|
// Show usage with status and archive count
|
||||||
|
let archive_display = if disk.archives_min == disk.archives_max {
|
||||||
|
format!("{}", disk.archives_min)
|
||||||
|
} else {
|
||||||
|
format!("{}-{}", disk.archives_min, disk.archives_max)
|
||||||
|
};
|
||||||
|
|
||||||
let usage_text = format!(
|
let usage_text = format!(
|
||||||
"Usage: {:.0}% {:.0}GB/{:.0}GB",
|
"Usage: ({}) {:.0}% {:.0}GB/{:.0}GB",
|
||||||
|
archive_display,
|
||||||
disk.disk_usage_percent,
|
disk.disk_usage_percent,
|
||||||
disk.disk_used_gb,
|
disk.disk_used_gb,
|
||||||
disk.disk_total_gb
|
disk.disk_total_gb
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.213"
|
version = "0.1.220"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -195,6 +195,8 @@ pub struct BackupDiskData {
|
|||||||
pub disk_total_gb: f32,
|
pub disk_total_gb: f32,
|
||||||
pub usage_status: Status,
|
pub usage_status: Status,
|
||||||
pub services: Vec<String>,
|
pub services: Vec<String>,
|
||||||
|
pub archives_min: i64,
|
||||||
|
pub archives_max: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AgentData {
|
impl AgentData {
|
||||||
|
|||||||
Reference in New Issue
Block a user