Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8bfd416327 | |||
| 85c6c624fb | |||
| eab3f17428 | |||
| 7ad149bbe4 | |||
| b444c88ea0 | |||
| 317cf76bd1 | |||
| 0db1a165b9 | |||
| 3c2955376d | |||
| f09ccabc7f | |||
| 43dd5a901a | |||
| 01e1f33b66 | |||
| ed6399b914 | |||
| 14618c59c6 | |||
| 2740de9b54 | |||
| 37f2650200 | |||
| 833010e270 | |||
| 549d9d1c72 | |||
| 9b84b70581 | |||
| 92c3ee3f2a | |||
| 1be55f765d | |||
| 2f94a4b853 | |||
| ff2b43827a | |||
| fac0188c6f | |||
| 6bb350f016 | |||
| 374b126446 |
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.186"
|
version = "0.1.191"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.186"
|
version = "0.1.191"
|
||||||
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.186"
|
version = "0.1.191"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.187"
|
version = "0.1.192"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ impl DiskCollector {
|
|||||||
let mut cmd = Command::new("lsblk");
|
let mut cmd = Command::new("lsblk");
|
||||||
cmd.args(&["-rn", "-o", "NAME,MOUNTPOINT"]);
|
cmd.args(&["-rn", "-o", "NAME,MOUNTPOINT"]);
|
||||||
|
|
||||||
let output = run_command_with_timeout(cmd, 5).await
|
let output = run_command_with_timeout(cmd, 2).await
|
||||||
.map_err(|e| CollectorError::SystemRead {
|
.map_err(|e| CollectorError::SystemRead {
|
||||||
path: "block devices".to_string(),
|
path: "block devices".to_string(),
|
||||||
error: e.to_string(),
|
error: e.to_string(),
|
||||||
@@ -427,7 +427,7 @@ impl DiskCollector {
|
|||||||
cmd.args(&["-a", &format!("/dev/{}", drive_name)]);
|
cmd.args(&["-a", &format!("/dev/{}", drive_name)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = run_command_with_timeout(cmd, 10).await
|
let output = run_command_with_timeout(cmd, 3).await
|
||||||
.map_err(|e| CollectorError::SystemRead {
|
.map_err(|e| CollectorError::SystemRead {
|
||||||
path: format!("SMART data for {}", drive_name),
|
path: format!("SMART data for {}", drive_name),
|
||||||
error: e.to_string(),
|
error: e.to_string(),
|
||||||
@@ -764,7 +764,7 @@ impl DiskCollector {
|
|||||||
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 = Command::new("timeout")
|
||||||
.args(&["5", "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))?;
|
||||||
|
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ impl MemoryCollector {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get usage data for all tmpfs mounts at once using df (with 3 second timeout)
|
// Get usage data for all tmpfs mounts at once using df (with 2 second timeout)
|
||||||
let mut df_args = vec!["3", "df", "--output=target,size,used", "--block-size=1"];
|
let mut df_args = vec!["2", "df", "--output=target,size,used", "--block-size=1"];
|
||||||
df_args.extend(tmpfs_mounts.iter().map(|s| s.as_str()));
|
df_args.extend(tmpfs_mounts.iter().map(|s| s.as_str()));
|
||||||
|
|
||||||
let df_output = std::process::Command::new("timeout")
|
let df_output = std::process::Command::new("timeout")
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ impl NetworkCollector {
|
|||||||
// Parse VLAN configuration
|
// Parse VLAN configuration
|
||||||
let vlan_map = Self::parse_vlan_config();
|
let vlan_map = Self::parse_vlan_config();
|
||||||
|
|
||||||
match Command::new("timeout").args(["3", "ip", "-j", "addr"]).output() {
|
match Command::new("timeout").args(["2", "ip", "-j", "addr"]).output() {
|
||||||
Ok(output) if output.status.success() => {
|
Ok(output) if output.status.success() => {
|
||||||
let json_str = String::from_utf8_lossy(&output.stdout);
|
let json_str = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ impl SystemdCollector {
|
|||||||
name: site_name.clone(),
|
name: site_name.clone(),
|
||||||
service_status: self.calculate_service_status(&site_name, &site_status),
|
service_status: self.calculate_service_status(&site_name, &site_status),
|
||||||
metrics,
|
metrics,
|
||||||
|
service_type: "nginx_site".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,12 +129,13 @@ impl SystemdCollector {
|
|||||||
name: container_name.clone(),
|
name: container_name.clone(),
|
||||||
service_status: self.calculate_service_status(&container_name, &container_status),
|
service_status: self.calculate_service_status(&container_name, &container_status),
|
||||||
metrics,
|
metrics,
|
||||||
|
service_type: "container".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Docker images
|
// Add Docker images
|
||||||
let docker_images = self.get_docker_images();
|
let docker_images = self.get_docker_images();
|
||||||
for (image_name, image_status, image_size_str, image_size_mb) in docker_images {
|
for (image_name, image_status, image_size_mb) in docker_images {
|
||||||
let mut metrics = Vec::new();
|
let mut metrics = Vec::new();
|
||||||
metrics.push(SubServiceMetric {
|
metrics.push(SubServiceMetric {
|
||||||
label: "size".to_string(),
|
label: "size".to_string(),
|
||||||
@@ -142,9 +144,10 @@ impl SystemdCollector {
|
|||||||
});
|
});
|
||||||
|
|
||||||
sub_services.push(SubServiceData {
|
sub_services.push(SubServiceData {
|
||||||
name: format!("{} ({})", image_name, image_size_str),
|
name: image_name.to_string(),
|
||||||
service_status: self.calculate_service_status(&image_name, &image_status),
|
service_status: self.calculate_service_status(&image_name, &image_status),
|
||||||
metrics,
|
metrics,
|
||||||
|
service_type: "image".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,18 +254,18 @@ impl SystemdCollector {
|
|||||||
|
|
||||||
/// Auto-discover interesting services to monitor
|
/// Auto-discover interesting services to monitor
|
||||||
fn discover_services_internal(&self) -> Result<(Vec<String>, std::collections::HashMap<String, ServiceStatusInfo>)> {
|
fn discover_services_internal(&self) -> Result<(Vec<String>, std::collections::HashMap<String, ServiceStatusInfo>)> {
|
||||||
// First: Get all service unit files (with 5 second timeout)
|
// First: Get all service unit files (with 3 second timeout)
|
||||||
let unit_files_output = Command::new("timeout")
|
let unit_files_output = Command::new("timeout")
|
||||||
.args(&["5", "systemctl", "list-unit-files", "--type=service", "--no-pager", "--plain"])
|
.args(&["3", "systemctl", "list-unit-files", "--type=service", "--no-pager", "--plain"])
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !unit_files_output.status.success() {
|
if !unit_files_output.status.success() {
|
||||||
return Err(anyhow::anyhow!("systemctl list-unit-files command failed"));
|
return Err(anyhow::anyhow!("systemctl list-unit-files command failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second: Get runtime status of all units (with 5 second timeout)
|
// Second: Get runtime status of all units (with 3 second timeout)
|
||||||
let units_status_output = Command::new("timeout")
|
let units_status_output = Command::new("timeout")
|
||||||
.args(&["5", "systemctl", "list-units", "--type=service", "--all", "--no-pager", "--plain"])
|
.args(&["3", "systemctl", "list-units", "--type=service", "--all", "--no-pager", "--plain"])
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !units_status_output.status.success() {
|
if !units_status_output.status.success() {
|
||||||
@@ -358,16 +361,16 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to systemctl if not in cache (with 3 second timeout)
|
// Fallback to systemctl if not in cache (with 2 second timeout)
|
||||||
let output = Command::new("timeout")
|
let output = Command::new("timeout")
|
||||||
.args(&["3", "systemctl", "is-active", &format!("{}.service", service)])
|
.args(&["2", "systemctl", "is-active", &format!("{}.service", service)])
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
let active_status = String::from_utf8(output.stdout)?.trim().to_string();
|
let active_status = String::from_utf8(output.stdout)?.trim().to_string();
|
||||||
|
|
||||||
// Get more detailed info (with 3 second timeout)
|
// Get more detailed info (with 2 second timeout)
|
||||||
let output = Command::new("timeout")
|
let output = Command::new("timeout")
|
||||||
.args(&["3", "systemctl", "show", &format!("{}.service", service), "--property=LoadState,ActiveState,SubState"])
|
.args(&["2", "systemctl", "show", &format!("{}.service", service), "--property=LoadState,ActiveState,SubState"])
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
let detailed_info = String::from_utf8(output.stdout)?;
|
let detailed_info = String::from_utf8(output.stdout)?;
|
||||||
@@ -427,9 +430,9 @@ impl SystemdCollector {
|
|||||||
return Ok(0.0);
|
return Ok(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No configured path - try to get WorkingDirectory from systemctl (with 3 second timeout)
|
// No configured path - try to get WorkingDirectory from systemctl (with 2 second timeout)
|
||||||
let output = Command::new("timeout")
|
let output = Command::new("timeout")
|
||||||
.args(&["3", "systemctl", "show", &format!("{}.service", service_name), "--property=WorkingDirectory"])
|
.args(&["2", "systemctl", "show", &format!("{}.service", service_name), "--property=WorkingDirectory"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| CollectorError::SystemRead {
|
.map_err(|e| CollectorError::SystemRead {
|
||||||
path: format!("WorkingDirectory for {}", service_name),
|
path: format!("WorkingDirectory for {}", service_name),
|
||||||
@@ -449,15 +452,15 @@ impl SystemdCollector {
|
|||||||
Ok(0.0)
|
Ok(0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get size of a directory in GB (with 5 second timeout)
|
/// Get size of a directory in GB (with 2 second timeout)
|
||||||
async fn get_directory_size(&self, path: &str) -> Option<f32> {
|
async fn get_directory_size(&self, path: &str) -> Option<f32> {
|
||||||
use super::run_command_with_timeout;
|
use super::run_command_with_timeout;
|
||||||
|
|
||||||
// Use -s (summary) and --apparent-size for speed, 5 second timeout
|
// Use -s (summary) and --apparent-size for speed, 2 second timeout
|
||||||
let mut cmd = Command::new("sudo");
|
let mut cmd = Command::new("sudo");
|
||||||
cmd.args(&["du", "-s", "--apparent-size", "--block-size=1", path]);
|
cmd.args(&["du", "-s", "--apparent-size", "--block-size=1", path]);
|
||||||
|
|
||||||
let output = run_command_with_timeout(cmd, 5).await.ok()?;
|
let output = run_command_with_timeout(cmd, 2).await.ok()?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
// Log permission errors for debugging but don't spam logs
|
// Log permission errors for debugging but don't spam logs
|
||||||
@@ -783,9 +786,9 @@ impl SystemdCollector {
|
|||||||
let mut containers = Vec::new();
|
let mut containers = Vec::new();
|
||||||
|
|
||||||
// Check if docker is available (cm-agent user is in docker group)
|
// Check if docker is available (cm-agent user is in docker group)
|
||||||
// Use -a to show ALL containers (running and stopped) with 5 second timeout
|
// Use -a to show ALL containers (running and stopped) with 3 second timeout
|
||||||
let output = Command::new("timeout")
|
let output = Command::new("timeout")
|
||||||
.args(&["5", "docker", "ps", "-a", "--format", "{{.Names}},{{.Status}}"])
|
.args(&["3", "docker", "ps", "-a", "--format", "{{.Names}},{{.Status}}"])
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
let output = match output {
|
let output = match output {
|
||||||
@@ -824,11 +827,11 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get docker images as sub-services
|
/// Get docker images as sub-services
|
||||||
fn get_docker_images(&self) -> Vec<(String, String, String, f32)> {
|
fn get_docker_images(&self) -> Vec<(String, String, f32)> {
|
||||||
let mut images = Vec::new();
|
let mut images = Vec::new();
|
||||||
// Check if docker is available (cm-agent user is in docker group) with 5 second timeout
|
// Check if docker is available (cm-agent user is in docker group) with 3 second timeout
|
||||||
let output = Command::new("timeout")
|
let output = Command::new("timeout")
|
||||||
.args(&["5", "docker", "images", "--format", "{{.Repository}}:{{.Tag}},{{.Size}}"])
|
.args(&["3", "docker", "images", "--format", "{{.Repository}}:{{.Tag}},{{.Size}}"])
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
let output = match output {
|
let output = match output {
|
||||||
@@ -865,9 +868,8 @@ impl SystemdCollector {
|
|||||||
let size_mb = self.parse_docker_size(size_str);
|
let size_mb = self.parse_docker_size(size_str);
|
||||||
|
|
||||||
images.push((
|
images.push((
|
||||||
format!("image_{}", image_name),
|
image_name.to_string(),
|
||||||
"active".to_string(), // Images are always "active" (present)
|
"inactive".to_string(), // Images are informational - use inactive for neutral display
|
||||||
size_str.to_string(),
|
|
||||||
size_mb
|
size_mb
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.187"
|
version = "0.1.192"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ struct ServiceInfo {
|
|||||||
disk_gb: Option<f32>,
|
disk_gb: Option<f32>,
|
||||||
metrics: Vec<(String, f32, Option<String>)>, // (label, value, unit)
|
metrics: Vec<(String, f32, Option<String>)>, // (label, value, unit)
|
||||||
widget_status: Status,
|
widget_status: Status,
|
||||||
|
service_type: String, // "nginx_site", "container", "image", or empty for parent services
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServicesWidget {
|
impl ServicesWidget {
|
||||||
@@ -179,6 +180,35 @@ impl ServicesWidget {
|
|||||||
};
|
};
|
||||||
let tree_symbol = if is_last { "└─" } else { "├─" };
|
let tree_symbol = if is_last { "└─" } else { "├─" };
|
||||||
|
|
||||||
|
// Docker images use docker whale icon
|
||||||
|
if info.service_type == "image" {
|
||||||
|
vec![
|
||||||
|
// Indentation and tree prefix
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
format!(" {} ", tree_symbol),
|
||||||
|
Typography::tree(),
|
||||||
|
),
|
||||||
|
// Docker icon (simple character for performance)
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
"D ".to_string(),
|
||||||
|
Style::default().fg(Theme::highlight()).bg(Theme::background()),
|
||||||
|
),
|
||||||
|
// Service name
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
format!("{:<18} ", short_name),
|
||||||
|
Style::default()
|
||||||
|
.fg(Theme::secondary_text())
|
||||||
|
.bg(Theme::background()),
|
||||||
|
),
|
||||||
|
// Status/metrics text
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
status_str,
|
||||||
|
Style::default()
|
||||||
|
.fg(Theme::secondary_text())
|
||||||
|
.bg(Theme::background()),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
} else {
|
||||||
vec![
|
vec![
|
||||||
// Indentation and tree prefix
|
// Indentation and tree prefix
|
||||||
ratatui::text::Span::styled(
|
ratatui::text::Span::styled(
|
||||||
@@ -206,6 +236,7 @@ impl ServicesWidget {
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Move selection up
|
/// Move selection up
|
||||||
pub fn select_previous(&mut self) {
|
pub fn select_previous(&mut self) {
|
||||||
@@ -282,6 +313,7 @@ impl Widget for ServicesWidget {
|
|||||||
disk_gb: Some(service.disk_gb),
|
disk_gb: Some(service.disk_gb),
|
||||||
metrics: Vec::new(), // Parent services don't have custom metrics
|
metrics: Vec::new(), // Parent services don't have custom metrics
|
||||||
widget_status: service.service_status,
|
widget_status: service.service_status,
|
||||||
|
service_type: String::new(), // Parent services have no type
|
||||||
};
|
};
|
||||||
self.parent_services.insert(service.name.clone(), parent_info);
|
self.parent_services.insert(service.name.clone(), parent_info);
|
||||||
|
|
||||||
@@ -299,6 +331,7 @@ impl Widget for ServicesWidget {
|
|||||||
disk_gb: None, // Not used for sub-services
|
disk_gb: None, // Not used for sub-services
|
||||||
metrics,
|
metrics,
|
||||||
widget_status: sub_service.service_status,
|
widget_status: sub_service.service_status,
|
||||||
|
service_type: sub_service.service_type.clone(),
|
||||||
};
|
};
|
||||||
sub_list.push((sub_service.name.clone(), sub_info));
|
sub_list.push((sub_service.name.clone(), sub_info));
|
||||||
}
|
}
|
||||||
@@ -342,6 +375,7 @@ impl ServicesWidget {
|
|||||||
disk_gb: None,
|
disk_gb: None,
|
||||||
metrics: Vec::new(),
|
metrics: Vec::new(),
|
||||||
widget_status: Status::Unknown,
|
widget_status: Status::Unknown,
|
||||||
|
service_type: String::new(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if metric.name.ends_with("_status") {
|
if metric.name.ends_with("_status") {
|
||||||
@@ -377,6 +411,7 @@ impl ServicesWidget {
|
|||||||
disk_gb: None,
|
disk_gb: None,
|
||||||
metrics: Vec::new(),
|
metrics: Vec::new(),
|
||||||
widget_status: Status::Unknown,
|
widget_status: Status::Unknown,
|
||||||
|
service_type: String::new(), // Unknown type in legacy path
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
&mut sub_service_list.last_mut().unwrap().1
|
&mut sub_service_list.last_mut().unwrap().1
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.187"
|
version = "0.1.192"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -149,6 +149,9 @@ pub struct SubServiceData {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub service_status: Status,
|
pub service_status: Status,
|
||||||
pub metrics: Vec<SubServiceMetric>,
|
pub metrics: Vec<SubServiceMetric>,
|
||||||
|
/// Type of sub-service: "nginx_site", "container", "image"
|
||||||
|
#[serde(default)]
|
||||||
|
pub service_type: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Individual metric for a sub-service
|
/// Individual metric for a sub-service
|
||||||
|
|||||||
Reference in New Issue
Block a user