Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1656f20e96 | |||
| dcd350ec2c | |||
| a34b095857 | |||
| 7362464b46 | |||
| c8b79576fa | |||
| f53df5440b | |||
| d1b0e2c431 | |||
| b1719a60fc |
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.267"
|
||||
version = "0.1.274"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@ -301,7 +301,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.267"
|
||||
version = "0.1.274"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@ -325,7 +325,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.267"
|
||||
version = "0.1.274"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.267"
|
||||
version = "0.1.275"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@ -21,7 +21,7 @@ impl BackupCollector {
|
||||
}
|
||||
}
|
||||
|
||||
/// Scan directory for all backup status files
|
||||
/// Scan directory for backup status file (nfs-backup.toml)
|
||||
async fn scan_status_files(&self) -> Result<Vec<PathBuf>, CollectorError> {
|
||||
let status_path = Path::new(&self.status_dir);
|
||||
|
||||
@ -30,30 +30,15 @@ impl BackupCollector {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let mut status_files = Vec::new();
|
||||
|
||||
match fs::read_dir(status_path) {
|
||||
Ok(entries) => {
|
||||
for entry in entries {
|
||||
if let Ok(entry) = entry {
|
||||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
if let Some(filename) = path.file_name().and_then(|n| n.to_str()) {
|
||||
if filename.starts_with("backup-status-") && filename.ends_with(".toml") {
|
||||
status_files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to read backup status directory: {}", e);
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
// Look for nfs-backup.toml (new NFS-based backup)
|
||||
let nfs_backup_file = status_path.join("nfs-backup.toml");
|
||||
if nfs_backup_file.exists() {
|
||||
return Ok(vec![nfs_backup_file]);
|
||||
}
|
||||
|
||||
Ok(status_files)
|
||||
// No backup status file found
|
||||
debug!("No nfs-backup.toml found in {}", self.status_dir);
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
/// Read a single backup status file
|
||||
@ -76,7 +61,7 @@ impl BackupCollector {
|
||||
/// Calculate backup status from TOML status field
|
||||
fn calculate_backup_status(status_str: &str) -> Status {
|
||||
match status_str.to_lowercase().as_str() {
|
||||
"success" => Status::Ok,
|
||||
"success" | "completed" => Status::Ok,
|
||||
"warning" => Status::Warning,
|
||||
"failed" | "error" => Status::Critical,
|
||||
_ => Status::Unknown,
|
||||
|
||||
@ -114,7 +114,7 @@ impl DiskCollector {
|
||||
let mut cmd = TokioCommand::new("lsblk");
|
||||
cmd.args(&["-rn", "-o", "NAME,MOUNTPOINT"]);
|
||||
|
||||
let output = run_command_with_timeout(cmd, 2).await
|
||||
let output = run_command_with_timeout(cmd, 10).await
|
||||
.map_err(|e| CollectorError::SystemRead {
|
||||
path: "block devices".to_string(),
|
||||
error: e.to_string(),
|
||||
@ -184,7 +184,7 @@ impl DiskCollector {
|
||||
/// Get filesystem info for a single mount point
|
||||
fn get_filesystem_info(&self, mount_point: &str) -> Result<(u64, u64), CollectorError> {
|
||||
let output = StdCommand::new("timeout")
|
||||
.args(&["2", "df", "--block-size=1", mount_point])
|
||||
.args(&["10", "df", "--block-size=1", mount_point])
|
||||
.output()
|
||||
.map_err(|e| CollectorError::SystemRead {
|
||||
path: format!("df {}", mount_point),
|
||||
@ -433,7 +433,7 @@ impl DiskCollector {
|
||||
cmd.args(&["-a", &format!("/dev/{}", drive_name)]);
|
||||
}
|
||||
|
||||
let output = run_command_with_timeout(cmd, 3).await
|
||||
let output = run_command_with_timeout(cmd, 15).await
|
||||
.map_err(|e| CollectorError::SystemRead {
|
||||
path: format!("SMART data for {}", drive_name),
|
||||
error: e.to_string(),
|
||||
@ -772,7 +772,7 @@ impl DiskCollector {
|
||||
fn get_drive_info_for_path(&self, path: &str) -> anyhow::Result<PoolDrive> {
|
||||
// Use lsblk to find the backing device with timeout
|
||||
let output = StdCommand::new("timeout")
|
||||
.args(&["2", "lsblk", "-rn", "-o", "NAME,MOUNTPOINT"])
|
||||
.args(&["10", "lsblk", "-rn", "-o", "NAME,MOUNTPOINT"])
|
||||
.output()
|
||||
.map_err(|e| anyhow::anyhow!("Failed to run lsblk: {}", e))?;
|
||||
|
||||
|
||||
@ -230,6 +230,38 @@ impl SystemdCollector {
|
||||
}
|
||||
}
|
||||
|
||||
if service_name == "nfs-server" && status_info.active_state == "active" {
|
||||
// Add NFS exports as sub-services
|
||||
let exports = self.get_nfs_exports();
|
||||
for (export_path, info) in exports {
|
||||
let display = if !info.is_empty() {
|
||||
format!("{} {}", export_path, info)
|
||||
} else {
|
||||
export_path
|
||||
};
|
||||
sub_services.push(SubServiceData {
|
||||
name: display,
|
||||
service_status: Status::Info,
|
||||
metrics: Vec::new(),
|
||||
service_type: "nfs_export".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (service_name == "smbd" || service_name == "samba-smbd") && status_info.active_state == "active" {
|
||||
// Add SMB shares as sub-services
|
||||
let shares = self.get_smb_shares();
|
||||
for (share_name, share_path) in shares {
|
||||
let metrics = Vec::new();
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("{}: {}", share_name, share_path),
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
service_type: "smb_share".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Create complete service data
|
||||
let service_data = ServiceData {
|
||||
name: service_name.clone(),
|
||||
@ -1011,6 +1043,148 @@ impl SystemdCollector {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get NFS exports from exportfs
|
||||
/// Returns a list of (export_path, info_string) tuples
|
||||
fn get_nfs_exports(&self) -> Vec<(String, String)> {
|
||||
let output = match Command::new("timeout")
|
||||
.args(["2", "exportfs", "-v"])
|
||||
.output()
|
||||
{
|
||||
Ok(output) if output.status.success() => output,
|
||||
_ => return Vec::new(),
|
||||
};
|
||||
|
||||
let exports_output = String::from_utf8_lossy(&output.stdout);
|
||||
let mut exports_map: std::collections::HashMap<String, Vec<(String, String)>> =
|
||||
std::collections::HashMap::new();
|
||||
let mut current_path: Option<String> = None;
|
||||
|
||||
for line in exports_output.lines() {
|
||||
let trimmed = line.trim();
|
||||
|
||||
if trimmed.is_empty() || trimmed.starts_with('#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if trimmed.starts_with('/') {
|
||||
// Export path line - may have network on same line or continuation
|
||||
let parts: Vec<&str> = trimmed.splitn(2, char::is_whitespace).collect();
|
||||
let path = parts[0].to_string();
|
||||
current_path = Some(path.clone());
|
||||
|
||||
// Check if network info is on the same line
|
||||
if parts.len() > 1 {
|
||||
let rest = parts[1].trim();
|
||||
if let Some(paren_pos) = rest.find('(') {
|
||||
let network = rest[..paren_pos].trim();
|
||||
|
||||
if let Some(end_paren) = rest.find(')') {
|
||||
let options = &rest[paren_pos+1..end_paren];
|
||||
let mode = if options.contains(",rw,") || options.ends_with(",rw") {
|
||||
"rw"
|
||||
} else {
|
||||
"ro"
|
||||
};
|
||||
|
||||
exports_map.entry(path)
|
||||
.or_insert_with(Vec::new)
|
||||
.push((network.to_string(), mode.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Some(ref path) = current_path {
|
||||
// Continuation line with network and options
|
||||
if let Some(paren_pos) = trimmed.find('(') {
|
||||
let network = trimmed[..paren_pos].trim();
|
||||
|
||||
if let Some(end_paren) = trimmed.find(')') {
|
||||
let options = &trimmed[paren_pos+1..end_paren];
|
||||
let mode = if options.contains(",rw,") || options.ends_with(",rw") {
|
||||
"rw"
|
||||
} else {
|
||||
"ro"
|
||||
};
|
||||
|
||||
exports_map.entry(path.clone())
|
||||
.or_insert_with(Vec::new)
|
||||
.push((network.to_string(), mode.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build display strings: "path: mode [networks]"
|
||||
let mut exports: Vec<(String, String)> = exports_map
|
||||
.into_iter()
|
||||
.map(|(path, mut entries)| {
|
||||
if entries.is_empty() {
|
||||
return (path, String::new());
|
||||
}
|
||||
|
||||
let mode = entries[0].1.clone();
|
||||
let networks: Vec<String> = entries.drain(..).map(|(n, _)| n).collect();
|
||||
let info = format!("{} [{}]", mode, networks.join(", "));
|
||||
(path, info)
|
||||
})
|
||||
.collect();
|
||||
|
||||
exports.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
exports
|
||||
}
|
||||
|
||||
/// Get SMB shares from smb.conf
|
||||
/// Returns a list of (share_name, share_path) tuples
|
||||
fn get_smb_shares(&self) -> Vec<(String, String)> {
|
||||
match std::fs::read_to_string("/etc/samba/smb.conf") {
|
||||
Ok(config) => {
|
||||
let mut shares = Vec::new();
|
||||
let mut current_share: Option<String> = None;
|
||||
let mut current_path: Option<String> = None;
|
||||
|
||||
for line in config.lines() {
|
||||
let line = line.trim();
|
||||
|
||||
// Skip comments and empty lines
|
||||
if line.is_empty() || line.starts_with('#') || line.starts_with(';') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Detect share section [sharename]
|
||||
if line.starts_with('[') && line.ends_with(']') {
|
||||
// Save previous share if we have both name and path
|
||||
if let (Some(name), Some(path)) = (current_share.take(), current_path.take()) {
|
||||
// Skip special sections
|
||||
if name != "global" && name != "homes" && name != "printers" {
|
||||
shares.push((name, path));
|
||||
}
|
||||
}
|
||||
|
||||
// Start new share
|
||||
let share_name = line[1..line.len()-1].trim().to_string();
|
||||
current_share = Some(share_name);
|
||||
current_path = None;
|
||||
}
|
||||
// Look for path = /some/path
|
||||
else if line.starts_with("path") && line.contains('=') {
|
||||
if let Some(path_value) = line.split('=').nth(1) {
|
||||
current_path = Some(path_value.trim().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't forget the last share
|
||||
if let (Some(name), Some(path)) = (current_share, current_path) {
|
||||
if name != "global" && name != "homes" && name != "printers" {
|
||||
shares.push((name, path));
|
||||
}
|
||||
}
|
||||
|
||||
shares
|
||||
}
|
||||
_ => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get nftables open ports grouped by protocol
|
||||
/// Returns: (tcp_ports_string, udp_ports_string)
|
||||
fn get_nftables_open_ports(&self) -> (String, String) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.267"
|
||||
version = "0.1.275"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@ -544,9 +544,8 @@ impl SystemWidget {
|
||||
"unknown".to_string()
|
||||
};
|
||||
|
||||
// Header: "Repo <complete timestamp>"
|
||||
let repo_text = format!("Repo {}", time_display);
|
||||
let repo_spans = StatusIcons::create_status_spans(self.backup_status, &repo_text);
|
||||
// Header: just the timestamp
|
||||
let repo_spans = StatusIcons::create_status_spans(self.backup_status, &time_display);
|
||||
lines.push(Line::from(repo_spans));
|
||||
|
||||
// List all repositories with archive count and size
|
||||
@ -554,8 +553,10 @@ impl SystemWidget {
|
||||
for (idx, repo) in self.backup_repositories.iter().enumerate() {
|
||||
let tree_char = if idx == repo_count - 1 { "└─" } else { "├─" };
|
||||
|
||||
// Format size: use MB for < 1GB, otherwise GB
|
||||
let size_display = if repo.repo_size_gb < 1.0 {
|
||||
// Format size: use kB for < 1MB, MB for < 1GB, otherwise GB
|
||||
let size_display = if repo.repo_size_gb < 0.001 {
|
||||
format!("{:.0}kB", repo.repo_size_gb * 1024.0 * 1024.0)
|
||||
} else if repo.repo_size_gb < 1.0 {
|
||||
format!("{:.0}MB", repo.repo_size_gb * 1024.0)
|
||||
} else {
|
||||
format!("{:.1}GB", repo.repo_size_gb)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.267"
|
||||
version = "0.1.275"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user