Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7a0dc27846 | |||
| 5bc250a738 | |||
| 5c3ac8b15e | |||
| bdfff942f7 | |||
| 47ab1e387d | |||
| 966ba27b1e | |||
| 6c6c9144bd | |||
| 3fdcec8047 | |||
| 1fcaf4a670 |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.232"
|
||||
version = "0.1.240"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -301,7 +301,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.232"
|
||||
version = "0.1.240"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@@ -325,7 +325,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.232"
|
||||
version = "0.1.240"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.232"
|
||||
version = "0.1.241"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -119,6 +119,81 @@ impl CpuCollector {
|
||||
utils::parse_u64(content.trim())
|
||||
}
|
||||
|
||||
/// Collect static CPU information from /proc/cpuinfo (only once at startup)
|
||||
async fn collect_cpu_info(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||
let content = utils::read_proc_file("/proc/cpuinfo")?;
|
||||
|
||||
let mut model_name: Option<String> = None;
|
||||
let mut core_count: u32 = 0;
|
||||
|
||||
for line in content.lines() {
|
||||
if line.starts_with("model name") {
|
||||
if let Some(colon_pos) = line.find(':') {
|
||||
let full_name = line[colon_pos + 1..].trim();
|
||||
// Extract just the model number (e.g., "i7-9700" from "Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz")
|
||||
let model = Self::extract_cpu_model(full_name);
|
||||
if model_name.is_none() {
|
||||
model_name = Some(model);
|
||||
}
|
||||
}
|
||||
} else if line.starts_with("processor") {
|
||||
core_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
agent_data.system.cpu.model_name = model_name;
|
||||
if core_count > 0 {
|
||||
agent_data.system.cpu.core_count = Some(core_count);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Extract CPU model number from full model name
|
||||
/// Examples:
|
||||
/// - "Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz" -> "i7-9700"
|
||||
/// - "AMD Ryzen 9 5950X 16-Core Processor" -> "Ryzen 9 5950X"
|
||||
fn extract_cpu_model(full_name: &str) -> String {
|
||||
// Look for common Intel patterns: i3, i5, i7, i9, Xeon
|
||||
if let Some(pos) = full_name.find("i3-") {
|
||||
if let Some(end) = full_name[pos..].find(' ') {
|
||||
return full_name[pos..pos + end].to_string();
|
||||
}
|
||||
}
|
||||
if let Some(pos) = full_name.find("i5-") {
|
||||
if let Some(end) = full_name[pos..].find(' ') {
|
||||
return full_name[pos..pos + end].to_string();
|
||||
}
|
||||
}
|
||||
if let Some(pos) = full_name.find("i7-") {
|
||||
if let Some(end) = full_name[pos..].find(' ') {
|
||||
return full_name[pos..pos + end].to_string();
|
||||
}
|
||||
}
|
||||
if let Some(pos) = full_name.find("i9-") {
|
||||
if let Some(end) = full_name[pos..].find(' ') {
|
||||
return full_name[pos..pos + end].to_string();
|
||||
}
|
||||
}
|
||||
|
||||
// Look for AMD Ryzen pattern
|
||||
if let Some(pos) = full_name.find("Ryzen") {
|
||||
// Extract "Ryzen X XXXX" pattern
|
||||
let after_ryzen = &full_name[pos..];
|
||||
let parts: Vec<&str> = after_ryzen.split_whitespace().collect();
|
||||
if parts.len() >= 3 {
|
||||
return format!("{} {} {}", parts[0], parts[1], parts[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: return first 20 characters or full name if shorter
|
||||
if full_name.len() > 20 {
|
||||
full_name[..20].to_string()
|
||||
} else {
|
||||
full_name.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// Collect CPU C-state (idle depth) and populate AgentData with top 3 C-states by usage
|
||||
async fn collect_cstate(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||
// Read C-state usage from first CPU (representative of overall system)
|
||||
@@ -192,6 +267,11 @@ impl Collector for CpuCollector {
|
||||
debug!("Collecting CPU metrics");
|
||||
let start = std::time::Instant::now();
|
||||
|
||||
// Collect static CPU info (only once at startup)
|
||||
if agent_data.system.cpu.model_name.is_none() || agent_data.system.cpu.core_count.is_none() {
|
||||
self.collect_cpu_info(agent_data).await?;
|
||||
}
|
||||
|
||||
// Collect load averages (always available)
|
||||
self.collect_load_averages(agent_data).await?;
|
||||
|
||||
|
||||
@@ -152,20 +152,20 @@ impl SystemdCollector {
|
||||
|
||||
sub_services.push(SubServiceData {
|
||||
name: image_name.to_string(),
|
||||
service_status: self.calculate_service_status(&image_name, &image_status),
|
||||
service_status: Status::Info, // Informational only, no status icon
|
||||
metrics,
|
||||
service_type: "image".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if service_name.contains("openvpn-vpn-connection") && status_info.active_state == "active" {
|
||||
if service_name == "openvpn-vpn-connection" && status_info.active_state == "active" {
|
||||
if let Some(external_ip) = self.get_vpn_external_ip() {
|
||||
let metrics = Vec::new();
|
||||
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("IP: {}", external_ip),
|
||||
service_status: Status::Ok,
|
||||
name: format!("ip: {}", external_ip),
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
service_type: "vpn_route".to_string(),
|
||||
});
|
||||
@@ -850,15 +850,16 @@ impl SystemdCollector {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get VPN external IP by querying through the openvpn-namespace
|
||||
/// Get VPN external IP by querying through the vpn namespace
|
||||
fn get_vpn_external_ip(&self) -> Option<String> {
|
||||
let output = Command::new("timeout")
|
||||
.args(&[
|
||||
"5",
|
||||
"sudo",
|
||||
"ip",
|
||||
"netns",
|
||||
"exec",
|
||||
"openvpn-namespace",
|
||||
"vpn",
|
||||
"curl",
|
||||
"-s",
|
||||
"--max-time",
|
||||
@@ -871,12 +872,10 @@ impl SystemdCollector {
|
||||
if output.status.success() {
|
||||
let ip = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||
if !ip.is_empty() && ip.contains('.') {
|
||||
debug!("VPN external IP: {}", ip);
|
||||
return Some(ip);
|
||||
}
|
||||
}
|
||||
|
||||
debug!("Failed to get VPN external IP");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.232"
|
||||
version = "0.1.241"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -142,6 +142,7 @@ impl Theme {
|
||||
/// Get color for status level
|
||||
pub fn status_color(status: Status) -> Color {
|
||||
match status {
|
||||
Status::Info => Self::muted_text(), // Gray for informational data
|
||||
Status::Ok => Self::success(),
|
||||
Status::Inactive => Self::muted_text(), // Gray for inactive services in service list
|
||||
Status::Pending => Self::highlight(), // Blue for pending
|
||||
@@ -240,6 +241,7 @@ impl StatusIcons {
|
||||
/// Get status icon symbol
|
||||
pub fn get_icon(status: Status) -> &'static str {
|
||||
match status {
|
||||
Status::Info => "", // No icon for informational data
|
||||
Status::Ok => "●",
|
||||
Status::Inactive => "○", // Empty circle for inactive services
|
||||
Status::Pending => "◉", // Hollow circle for pending
|
||||
@@ -254,6 +256,7 @@ impl StatusIcons {
|
||||
pub fn create_status_spans(status: Status, text: &str) -> Vec<ratatui::text::Span<'static>> {
|
||||
let icon = Self::get_icon(status);
|
||||
let status_color = match status {
|
||||
Status::Info => Theme::muted_text(), // Gray for info
|
||||
Status::Ok => Theme::success(), // Green
|
||||
Status::Inactive => Theme::muted_text(), // Gray for inactive services
|
||||
Status::Pending => Theme::highlight(), // Blue
|
||||
|
||||
@@ -156,6 +156,7 @@ impl ServicesWidget {
|
||||
|
||||
// Convert Status enum to display text
|
||||
let status_str = match info.widget_status {
|
||||
Status::Info => "", // Shouldn't happen for parent services
|
||||
Status::Ok => "active",
|
||||
Status::Inactive => "inactive",
|
||||
Status::Critical => "failed",
|
||||
@@ -239,6 +240,7 @@ impl ServicesWidget {
|
||||
// Get status icon and text
|
||||
let icon = StatusIcons::get_icon(info.widget_status);
|
||||
let status_color = match info.widget_status {
|
||||
Status::Info => Theme::muted_text(),
|
||||
Status::Ok => Theme::success(),
|
||||
Status::Inactive => Theme::muted_text(),
|
||||
Status::Pending => Theme::highlight(),
|
||||
@@ -259,6 +261,7 @@ impl ServicesWidget {
|
||||
} else {
|
||||
// Convert Status enum to display text for sub-services
|
||||
match info.widget_status {
|
||||
Status::Info => "",
|
||||
Status::Ok => "active",
|
||||
Status::Inactive => "inactive",
|
||||
Status::Critical => "failed",
|
||||
@@ -270,34 +273,34 @@ impl ServicesWidget {
|
||||
};
|
||||
let tree_symbol = if is_last { "└─" } else { "├─" };
|
||||
|
||||
// Docker images use docker whale icon
|
||||
if info.service_type == "image" {
|
||||
vec![
|
||||
if info.widget_status == Status::Info {
|
||||
// Informational data - no status icon, show metrics if available
|
||||
let mut spans = 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
|
||||
// Service name (no icon)
|
||||
ratatui::text::Span::styled(
|
||||
format!("{:<18} ", short_name),
|
||||
Style::default()
|
||||
.fg(Theme::secondary_text())
|
||||
.bg(Theme::background()),
|
||||
),
|
||||
// Status/metrics text
|
||||
ratatui::text::Span::styled(
|
||||
];
|
||||
|
||||
// Add metrics if available (e.g., Docker image size)
|
||||
if !status_str.is_empty() {
|
||||
spans.push(ratatui::text::Span::styled(
|
||||
status_str,
|
||||
Style::default()
|
||||
.fg(Theme::secondary_text())
|
||||
.bg(Theme::background()),
|
||||
),
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
spans
|
||||
} else {
|
||||
vec![
|
||||
// Indentation and tree prefix
|
||||
|
||||
@@ -27,6 +27,8 @@ pub struct SystemWidget {
|
||||
cpu_load_5min: Option<f32>,
|
||||
cpu_load_15min: Option<f32>,
|
||||
cpu_cstates: Vec<cm_dashboard_shared::CStateInfo>,
|
||||
cpu_model_name: Option<String>,
|
||||
cpu_core_count: Option<u32>,
|
||||
cpu_status: Status,
|
||||
|
||||
// Memory metrics
|
||||
@@ -97,6 +99,8 @@ impl SystemWidget {
|
||||
cpu_load_5min: None,
|
||||
cpu_load_15min: None,
|
||||
cpu_cstates: Vec::new(),
|
||||
cpu_model_name: None,
|
||||
cpu_core_count: None,
|
||||
cpu_status: Status::Unknown,
|
||||
memory_usage_percent: None,
|
||||
memory_used_gb: None,
|
||||
@@ -184,6 +188,8 @@ impl Widget for SystemWidget {
|
||||
self.cpu_load_5min = Some(cpu.load_5min);
|
||||
self.cpu_load_15min = Some(cpu.load_15min);
|
||||
self.cpu_cstates = cpu.cstates.clone();
|
||||
self.cpu_model_name = cpu.model_name.clone();
|
||||
self.cpu_core_count = cpu.core_count;
|
||||
self.cpu_status = Status::Ok;
|
||||
|
||||
// Extract memory data directly
|
||||
@@ -830,11 +836,31 @@ impl SystemWidget {
|
||||
lines.push(Line::from(cpu_spans));
|
||||
|
||||
let cstate_text = self.format_cpu_cstate();
|
||||
let has_cpu_info = self.cpu_model_name.is_some() || self.cpu_core_count.is_some();
|
||||
let cstate_tree = if has_cpu_info { " ├─ " } else { " └─ " };
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" └─ ", Typography::tree()),
|
||||
Span::styled(cstate_tree, Typography::tree()),
|
||||
Span::styled(format!("C-state: {}", cstate_text), Typography::secondary())
|
||||
]));
|
||||
|
||||
// CPU model and core count (if available)
|
||||
if let (Some(model), Some(cores)) = (&self.cpu_model_name, self.cpu_core_count) {
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" └─ ", Typography::tree()),
|
||||
Span::styled(format!("{} ({} cores)", model, cores), Typography::secondary())
|
||||
]));
|
||||
} else if let Some(model) = &self.cpu_model_name {
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" └─ ", Typography::tree()),
|
||||
Span::styled(model.clone(), Typography::secondary())
|
||||
]));
|
||||
} else if let Some(cores) = self.cpu_core_count {
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" └─ ", Typography::tree()),
|
||||
Span::styled(format!("{} cores", cores), Typography::secondary())
|
||||
]));
|
||||
}
|
||||
|
||||
// RAM section
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled("RAM:", Typography::widget_title())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.232"
|
||||
version = "0.1.241"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -57,6 +57,11 @@ pub struct CpuData {
|
||||
pub temperature_celsius: Option<f32>,
|
||||
pub load_status: Status,
|
||||
pub temperature_status: Status,
|
||||
// Static CPU information (collected once at startup)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub model_name: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub core_count: Option<u32>,
|
||||
}
|
||||
|
||||
/// Memory monitoring data
|
||||
@@ -219,6 +224,8 @@ impl AgentData {
|
||||
temperature_celsius: None,
|
||||
load_status: Status::Unknown,
|
||||
temperature_status: Status::Unknown,
|
||||
model_name: None,
|
||||
core_count: None,
|
||||
},
|
||||
memory: MemoryData {
|
||||
usage_percent: 0.0,
|
||||
|
||||
@@ -82,12 +82,13 @@ impl MetricValue {
|
||||
/// Health status for metrics
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum Status {
|
||||
Inactive, // Lowest priority
|
||||
Unknown, //
|
||||
Offline, //
|
||||
Pending, //
|
||||
Ok, // 5th place - good status has higher priority than unknown states
|
||||
Warning, //
|
||||
Info, // Lowest priority - informational data with no status (no icon)
|
||||
Inactive, //
|
||||
Unknown, //
|
||||
Offline, //
|
||||
Pending, //
|
||||
Ok, // Good status has higher priority than unknown states
|
||||
Warning, //
|
||||
Critical, // Highest priority
|
||||
}
|
||||
|
||||
@@ -223,6 +224,17 @@ impl HysteresisThresholds {
|
||||
Status::Ok
|
||||
}
|
||||
}
|
||||
Status::Info => {
|
||||
// Informational data shouldn't be used with hysteresis calculations
|
||||
// Treat like Unknown if it somehow ends up here
|
||||
if value >= self.critical_high {
|
||||
Status::Critical
|
||||
} else if value >= self.warning_high {
|
||||
Status::Warning
|
||||
} else {
|
||||
Status::Ok
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user