Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6817537a8 | |||
| 2189d34b16 | |||
| 28cfd5758f | |||
| 5deb8cf8d8 | |||
| 0e01813ff5 |
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.204"
|
version = "0.1.206"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.204"
|
version = "0.1.207"
|
||||||
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.204"
|
version = "0.1.207"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.205"
|
version = "0.1.208"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -119,36 +119,40 @@ impl CpuCollector {
|
|||||||
utils::parse_u64(content.trim())
|
utils::parse_u64(content.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collect CPU frequency and populate AgentData
|
/// Collect CPU C-state (idle depth) and populate AgentData
|
||||||
async fn collect_frequency(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
async fn collect_cstate(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||||
// Try scaling frequency first (more accurate for current frequency)
|
// Read C-state usage from first CPU (representative of overall system)
|
||||||
if let Ok(freq) =
|
// C-states indicate CPU idle depth: C1=light sleep, C6=deep sleep, C10=deepest
|
||||||
utils::read_proc_file("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")
|
|
||||||
{
|
|
||||||
if let Ok(freq_khz) = utils::parse_u64(freq.trim()) {
|
|
||||||
let freq_mhz = freq_khz as f32 / 1000.0;
|
|
||||||
agent_data.system.cpu.frequency_mhz = freq_mhz;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: parse /proc/cpuinfo for base frequency
|
let mut deepest_state = String::from("C0"); // Default to active
|
||||||
if let Ok(content) = utils::read_proc_file("/proc/cpuinfo") {
|
let mut max_time: u64 = 0;
|
||||||
for line in content.lines() {
|
|
||||||
if line.starts_with("cpu MHz") {
|
// Check C-states from CPU0
|
||||||
if let Some(freq_str) = line.split(':').nth(1) {
|
for state_num in 0..=10 {
|
||||||
if let Ok(freq_mhz) = utils::parse_f32(freq_str) {
|
let time_path = format!("/sys/devices/system/cpu/cpu0/cpuidle/state{}/time", state_num);
|
||||||
agent_data.system.cpu.frequency_mhz = freq_mhz;
|
let name_path = format!("/sys/devices/system/cpu/cpu0/cpuidle/state{}/name", state_num);
|
||||||
return Ok(());
|
|
||||||
|
if let Ok(time_str) = utils::read_proc_file(&time_path) {
|
||||||
|
if let Ok(time) = utils::parse_u64(time_str.trim()) {
|
||||||
|
if time > max_time {
|
||||||
|
// This state has most accumulated time
|
||||||
|
if let Ok(name) = utils::read_proc_file(&name_path) {
|
||||||
|
let state_name = name.trim().to_string();
|
||||||
|
// Skip POLL state (not real idle)
|
||||||
|
if state_name != "POLL" {
|
||||||
|
max_time = time;
|
||||||
|
deepest_state = state_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break; // Only need first CPU entry
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// No more states available
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("CPU frequency not available");
|
agent_data.system.cpu.cstate = deepest_state;
|
||||||
// Leave frequency as 0.0 if not available
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,8 +169,8 @@ impl Collector for CpuCollector {
|
|||||||
// Collect temperature (optional)
|
// Collect temperature (optional)
|
||||||
self.collect_temperature(agent_data).await?;
|
self.collect_temperature(agent_data).await?;
|
||||||
|
|
||||||
// Collect frequency (optional)
|
// Collect C-state (CPU idle depth)
|
||||||
self.collect_frequency(agent_data).await?;
|
self.collect_cstate(agent_data).await?;
|
||||||
|
|
||||||
let duration = start.elapsed();
|
let duration = start.elapsed();
|
||||||
debug!("CPU collection completed in {:?}", duration);
|
debug!("CPU collection completed in {:?}", duration);
|
||||||
|
|||||||
@@ -43,9 +43,10 @@ struct ServiceCacheState {
|
|||||||
/// Cached service status information from systemctl list-units
|
/// Cached service status information from systemctl list-units
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct ServiceStatusInfo {
|
struct ServiceStatusInfo {
|
||||||
load_state: String,
|
|
||||||
active_state: String,
|
active_state: String,
|
||||||
sub_state: String,
|
memory_bytes: Option<u64>,
|
||||||
|
restart_count: Option<u32>,
|
||||||
|
start_timestamp: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemdCollector {
|
impl SystemdCollector {
|
||||||
@@ -86,11 +87,20 @@ impl SystemdCollector {
|
|||||||
let mut complete_service_data = Vec::new();
|
let mut complete_service_data = Vec::new();
|
||||||
for service_name in &monitored_services {
|
for service_name in &monitored_services {
|
||||||
match self.get_service_status(service_name) {
|
match self.get_service_status(service_name) {
|
||||||
Ok((active_status, _detailed_info)) => {
|
Ok(status_info) => {
|
||||||
let mut sub_services = Vec::new();
|
let mut sub_services = Vec::new();
|
||||||
|
|
||||||
|
// Calculate uptime if we have start timestamp
|
||||||
|
let uptime_seconds = status_info.start_timestamp.and_then(|start| {
|
||||||
|
let now = std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.ok()?
|
||||||
|
.as_secs();
|
||||||
|
Some(now.saturating_sub(start))
|
||||||
|
});
|
||||||
|
|
||||||
// Sub-service metrics for specific services (always include cached results)
|
// Sub-service metrics for specific services (always include cached results)
|
||||||
if service_name.contains("nginx") && active_status == "active" {
|
if service_name.contains("nginx") && status_info.active_state == "active" {
|
||||||
let nginx_sites = self.get_nginx_site_metrics();
|
let nginx_sites = self.get_nginx_site_metrics();
|
||||||
for (site_name, latency_ms) in nginx_sites {
|
for (site_name, latency_ms) in nginx_sites {
|
||||||
let site_status = if latency_ms >= 0.0 && latency_ms < self.config.nginx_latency_critical_ms {
|
let site_status = if latency_ms >= 0.0 && latency_ms < self.config.nginx_latency_critical_ms {
|
||||||
@@ -115,7 +125,7 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if service_name.contains("docker") && active_status == "active" {
|
if service_name.contains("docker") && status_info.active_state == "active" {
|
||||||
let docker_containers = self.get_docker_containers();
|
let docker_containers = self.get_docker_containers();
|
||||||
for (container_name, container_status) in docker_containers {
|
for (container_name, container_status) in docker_containers {
|
||||||
// For now, docker containers have no additional metrics
|
// For now, docker containers have no additional metrics
|
||||||
@@ -153,8 +163,11 @@ impl SystemdCollector {
|
|||||||
let service_data = ServiceData {
|
let service_data = ServiceData {
|
||||||
name: service_name.clone(),
|
name: service_name.clone(),
|
||||||
user_stopped: false, // TODO: Integrate with service tracker
|
user_stopped: false, // TODO: Integrate with service tracker
|
||||||
service_status: self.calculate_service_status(service_name, &active_status),
|
service_status: self.calculate_service_status(service_name, &status_info.active_state),
|
||||||
sub_services,
|
sub_services,
|
||||||
|
memory_bytes: status_info.memory_bytes,
|
||||||
|
restart_count: status_info.restart_count,
|
||||||
|
uptime_seconds,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add to AgentData and cache
|
// Add to AgentData and cache
|
||||||
@@ -290,14 +303,13 @@ impl SystemdCollector {
|
|||||||
let fields: Vec<&str> = line.split_whitespace().collect();
|
let fields: Vec<&str> = line.split_whitespace().collect();
|
||||||
if fields.len() >= 4 && fields[0].ends_with(".service") {
|
if fields.len() >= 4 && fields[0].ends_with(".service") {
|
||||||
let service_name = fields[0].trim_end_matches(".service");
|
let service_name = fields[0].trim_end_matches(".service");
|
||||||
let load_state = fields.get(1).unwrap_or(&"unknown").to_string();
|
|
||||||
let active_state = fields.get(2).unwrap_or(&"unknown").to_string();
|
let active_state = fields.get(2).unwrap_or(&"unknown").to_string();
|
||||||
let sub_state = fields.get(3).unwrap_or(&"unknown").to_string();
|
|
||||||
|
|
||||||
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
||||||
load_state,
|
|
||||||
active_state,
|
active_state,
|
||||||
sub_state,
|
memory_bytes: None,
|
||||||
|
restart_count: None,
|
||||||
|
start_timestamp: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,9 +318,10 @@ impl SystemdCollector {
|
|||||||
for service_name in &all_service_names {
|
for service_name in &all_service_names {
|
||||||
if !status_cache.contains_key(service_name) {
|
if !status_cache.contains_key(service_name) {
|
||||||
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
||||||
load_state: "not-loaded".to_string(),
|
|
||||||
active_state: "inactive".to_string(),
|
active_state: "inactive".to_string(),
|
||||||
sub_state: "dead".to_string(),
|
memory_bytes: None,
|
||||||
|
restart_count: None,
|
||||||
|
start_timestamp: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -340,36 +353,60 @@ impl SystemdCollector {
|
|||||||
Ok((services, status_cache))
|
Ok((services, status_cache))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get service status from cache (if available) or fallback to systemctl
|
/// Get service status with detailed metrics from systemctl
|
||||||
fn get_service_status(&self, service: &str) -> Result<(String, String)> {
|
fn get_service_status(&self, service: &str) -> Result<ServiceStatusInfo> {
|
||||||
// Try to get status from cache first
|
// Always fetch fresh data to get detailed metrics (memory, restarts, uptime)
|
||||||
if let Ok(state) = self.state.read() {
|
// Note: Cache in service_status_cache only has basic active_state from discovery,
|
||||||
if let Some(cached_info) = state.service_status_cache.get(service) {
|
// with all detailed metrics set to None. We need fresh systemctl show data.
|
||||||
let active_status = cached_info.active_state.clone();
|
|
||||||
let detailed_info = format!(
|
let output = Command::new("timeout")
|
||||||
"LoadState={}\nActiveState={}\nSubState={}",
|
.args(&[
|
||||||
cached_info.load_state,
|
"2",
|
||||||
cached_info.active_state,
|
"systemctl",
|
||||||
cached_info.sub_state
|
"show",
|
||||||
);
|
&format!("{}.service", service),
|
||||||
return Ok((active_status, detailed_info));
|
"--property=LoadState,ActiveState,SubState,MemoryCurrent,NRestarts,ExecMainStartTimestamp"
|
||||||
|
])
|
||||||
|
.output()?;
|
||||||
|
|
||||||
|
let output_str = String::from_utf8(output.stdout)?;
|
||||||
|
|
||||||
|
// Parse properties
|
||||||
|
let mut active_state = String::new();
|
||||||
|
let mut memory_bytes = None;
|
||||||
|
let mut restart_count = None;
|
||||||
|
let mut start_timestamp = None;
|
||||||
|
|
||||||
|
for line in output_str.lines() {
|
||||||
|
if let Some(value) = line.strip_prefix("ActiveState=") {
|
||||||
|
active_state = value.to_string();
|
||||||
|
} else if let Some(value) = line.strip_prefix("MemoryCurrent=") {
|
||||||
|
if value != "[not set]" {
|
||||||
|
memory_bytes = value.parse().ok();
|
||||||
|
}
|
||||||
|
} else if let Some(value) = line.strip_prefix("NRestarts=") {
|
||||||
|
restart_count = value.parse().ok();
|
||||||
|
} else if let Some(value) = line.strip_prefix("ExecMainStartTimestamp=") {
|
||||||
|
if value != "[not set]" && !value.is_empty() {
|
||||||
|
// Parse timestamp to seconds since epoch
|
||||||
|
if let Ok(output) = Command::new("date")
|
||||||
|
.args(&["+%s", "-d", value])
|
||||||
|
.output()
|
||||||
|
{
|
||||||
|
if let Ok(timestamp_str) = String::from_utf8(output.stdout) {
|
||||||
|
start_timestamp = timestamp_str.trim().parse().ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to systemctl if not in cache (with 2 second timeout)
|
Ok(ServiceStatusInfo {
|
||||||
let output = Command::new("timeout")
|
active_state,
|
||||||
.args(&["2", "systemctl", "is-active", &format!("{}.service", service)])
|
memory_bytes,
|
||||||
.output()?;
|
restart_count,
|
||||||
|
start_timestamp,
|
||||||
let active_status = String::from_utf8(output.stdout)?.trim().to_string();
|
})
|
||||||
|
|
||||||
// Get more detailed info (with 2 second timeout)
|
|
||||||
let output = Command::new("timeout")
|
|
||||||
.args(&["2", "systemctl", "show", &format!("{}.service", service), "--property=LoadState,ActiveState,SubState"])
|
|
||||||
.output()?;
|
|
||||||
|
|
||||||
let detailed_info = String::from_utf8(output.stdout)?;
|
|
||||||
Ok((active_status, detailed_info))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if service name matches pattern (supports wildcards like nginx*)
|
/// Check if service name matches pattern (supports wildcards like nginx*)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.205"
|
version = "0.1.208"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ struct ServiceInfo {
|
|||||||
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
|
service_type: String, // "nginx_site", "container", "image", or empty for parent services
|
||||||
|
memory_bytes: Option<u64>,
|
||||||
|
restart_count: Option<u32>,
|
||||||
|
uptime_seconds: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServicesWidget {
|
impl ServicesWidget {
|
||||||
@@ -84,7 +87,7 @@ impl ServicesWidget {
|
|||||||
// Convert Status enum to display text
|
// Convert Status enum to display text
|
||||||
let status_str = match info.widget_status {
|
let status_str = match info.widget_status {
|
||||||
Status::Ok => "active",
|
Status::Ok => "active",
|
||||||
Status::Inactive => "inactive",
|
Status::Inactive => "inactive",
|
||||||
Status::Critical => "failed",
|
Status::Critical => "failed",
|
||||||
Status::Pending => "pending",
|
Status::Pending => "pending",
|
||||||
Status::Warning => "warning",
|
Status::Warning => "warning",
|
||||||
@@ -92,9 +95,43 @@ impl ServicesWidget {
|
|||||||
Status::Offline => "offline",
|
Status::Offline => "offline",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Format memory
|
||||||
|
let memory_str = info.memory_bytes.map_or("-".to_string(), |bytes| {
|
||||||
|
let mb = bytes as f64 / (1024.0 * 1024.0);
|
||||||
|
if mb >= 1000.0 {
|
||||||
|
format!("{:.1}G", mb / 1024.0)
|
||||||
|
} else {
|
||||||
|
format!("{:.0}M", mb)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Format uptime
|
||||||
|
let uptime_str = info.uptime_seconds.map_or("-".to_string(), |secs| {
|
||||||
|
let days = secs / 86400;
|
||||||
|
let hours = (secs % 86400) / 3600;
|
||||||
|
let mins = (secs % 3600) / 60;
|
||||||
|
|
||||||
|
if days > 0 {
|
||||||
|
format!("{}d{}h", days, hours)
|
||||||
|
} else if hours > 0 {
|
||||||
|
format!("{}h{}m", hours, mins)
|
||||||
|
} else {
|
||||||
|
format!("{}m", mins)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Format restarts (show "!" if > 0 to indicate instability)
|
||||||
|
let restart_str = info.restart_count.map_or("-".to_string(), |count| {
|
||||||
|
if count > 0 {
|
||||||
|
format!("!{}", count)
|
||||||
|
} else {
|
||||||
|
"0".to_string()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{:<23} {:<10}",
|
"{:<23} {:<10} {:<8} {:<8} {:<5}",
|
||||||
short_name, status_str
|
short_name, status_str, memory_str, uptime_str, restart_str
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,6 +317,9 @@ impl Widget for ServicesWidget {
|
|||||||
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
|
service_type: String::new(), // Parent services have no type
|
||||||
|
memory_bytes: service.memory_bytes,
|
||||||
|
restart_count: service.restart_count,
|
||||||
|
uptime_seconds: service.uptime_seconds,
|
||||||
};
|
};
|
||||||
self.parent_services.insert(service.name.clone(), parent_info);
|
self.parent_services.insert(service.name.clone(), parent_info);
|
||||||
|
|
||||||
@@ -296,6 +336,9 @@ impl Widget for ServicesWidget {
|
|||||||
metrics,
|
metrics,
|
||||||
widget_status: sub_service.service_status,
|
widget_status: sub_service.service_status,
|
||||||
service_type: sub_service.service_type.clone(),
|
service_type: sub_service.service_type.clone(),
|
||||||
|
memory_bytes: None, // Sub-services don't have individual metrics yet
|
||||||
|
restart_count: None,
|
||||||
|
uptime_seconds: None,
|
||||||
};
|
};
|
||||||
sub_list.push((sub_service.name.clone(), sub_info));
|
sub_list.push((sub_service.name.clone(), sub_info));
|
||||||
}
|
}
|
||||||
@@ -338,6 +381,9 @@ impl ServicesWidget {
|
|||||||
metrics: Vec::new(),
|
metrics: Vec::new(),
|
||||||
widget_status: Status::Unknown,
|
widget_status: Status::Unknown,
|
||||||
service_type: String::new(),
|
service_type: String::new(),
|
||||||
|
memory_bytes: None,
|
||||||
|
restart_count: None,
|
||||||
|
uptime_seconds: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
if metric.name.ends_with("_status") {
|
if metric.name.ends_with("_status") {
|
||||||
@@ -364,6 +410,9 @@ impl ServicesWidget {
|
|||||||
metrics: Vec::new(),
|
metrics: Vec::new(),
|
||||||
widget_status: Status::Unknown,
|
widget_status: Status::Unknown,
|
||||||
service_type: String::new(), // Unknown type in legacy path
|
service_type: String::new(), // Unknown type in legacy path
|
||||||
|
memory_bytes: None,
|
||||||
|
restart_count: None,
|
||||||
|
uptime_seconds: None,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
&mut sub_service_list.last_mut().unwrap().1
|
&mut sub_service_list.last_mut().unwrap().1
|
||||||
@@ -429,8 +478,8 @@ impl ServicesWidget {
|
|||||||
|
|
||||||
// Header
|
// Header
|
||||||
let header = format!(
|
let header = format!(
|
||||||
"{:<25} {:<10}",
|
"{:<25} {:<10} {:<8} {:<8} {:<5}",
|
||||||
"Service:", "Status:"
|
"Service:", "Status:", "RAM:", "Uptime:", "↻:"
|
||||||
);
|
);
|
||||||
let header_para = Paragraph::new(header).style(Typography::muted());
|
let header_para = Paragraph::new(header).style(Typography::muted());
|
||||||
frame.render_widget(header_para, content_chunks[0]);
|
frame.render_widget(header_para, content_chunks[0]);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub struct SystemWidget {
|
|||||||
cpu_load_1min: Option<f32>,
|
cpu_load_1min: Option<f32>,
|
||||||
cpu_load_5min: Option<f32>,
|
cpu_load_5min: Option<f32>,
|
||||||
cpu_load_15min: Option<f32>,
|
cpu_load_15min: Option<f32>,
|
||||||
cpu_frequency: Option<f32>,
|
cpu_cstate: Option<String>,
|
||||||
cpu_status: Status,
|
cpu_status: Status,
|
||||||
|
|
||||||
// Memory metrics
|
// Memory metrics
|
||||||
@@ -102,7 +102,7 @@ impl SystemWidget {
|
|||||||
cpu_load_1min: None,
|
cpu_load_1min: None,
|
||||||
cpu_load_5min: None,
|
cpu_load_5min: None,
|
||||||
cpu_load_15min: None,
|
cpu_load_15min: None,
|
||||||
cpu_frequency: None,
|
cpu_cstate: None,
|
||||||
cpu_status: Status::Unknown,
|
cpu_status: Status::Unknown,
|
||||||
memory_usage_percent: None,
|
memory_usage_percent: None,
|
||||||
memory_used_gb: None,
|
memory_used_gb: None,
|
||||||
@@ -137,11 +137,11 @@ impl SystemWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format CPU frequency
|
/// Format CPU C-state (idle depth)
|
||||||
fn format_cpu_frequency(&self) -> String {
|
fn format_cpu_cstate(&self) -> String {
|
||||||
match self.cpu_frequency {
|
match &self.cpu_cstate {
|
||||||
Some(freq) => format!("{:.0} MHz", freq),
|
Some(cstate) => cstate.clone(),
|
||||||
None => "— MHz".to_string(),
|
None => "—".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ impl Widget for SystemWidget {
|
|||||||
self.cpu_load_1min = Some(cpu.load_1min);
|
self.cpu_load_1min = Some(cpu.load_1min);
|
||||||
self.cpu_load_5min = Some(cpu.load_5min);
|
self.cpu_load_5min = Some(cpu.load_5min);
|
||||||
self.cpu_load_15min = Some(cpu.load_15min);
|
self.cpu_load_15min = Some(cpu.load_15min);
|
||||||
self.cpu_frequency = Some(cpu.frequency_mhz);
|
self.cpu_cstate = Some(cpu.cstate.clone());
|
||||||
self.cpu_status = Status::Ok;
|
self.cpu_status = Status::Ok;
|
||||||
|
|
||||||
// Extract memory data directly
|
// Extract memory data directly
|
||||||
@@ -832,10 +832,10 @@ impl SystemWidget {
|
|||||||
);
|
);
|
||||||
lines.push(Line::from(cpu_spans));
|
lines.push(Line::from(cpu_spans));
|
||||||
|
|
||||||
let freq_text = self.format_cpu_frequency();
|
let cstate_text = self.format_cpu_cstate();
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(" └─ ", Typography::tree()),
|
Span::styled(" └─ ", Typography::tree()),
|
||||||
Span::styled(format!("Freq: {}", freq_text), Typography::secondary())
|
Span::styled(format!("C-state: {}", cstate_text), Typography::secondary())
|
||||||
]));
|
]));
|
||||||
|
|
||||||
// RAM section
|
// RAM section
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.205"
|
version = "0.1.208"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ pub struct CpuData {
|
|||||||
pub load_1min: f32,
|
pub load_1min: f32,
|
||||||
pub load_5min: f32,
|
pub load_5min: f32,
|
||||||
pub load_15min: f32,
|
pub load_15min: f32,
|
||||||
pub frequency_mhz: f32,
|
pub cstate: String, // Deepest C-state in use (C1, C6, C10, etc.) - indicates CPU idle depth
|
||||||
pub temperature_celsius: Option<f32>,
|
pub temperature_celsius: Option<f32>,
|
||||||
pub load_status: Status,
|
pub load_status: Status,
|
||||||
pub temperature_status: Status,
|
pub temperature_status: Status,
|
||||||
@@ -139,6 +139,12 @@ pub struct ServiceData {
|
|||||||
pub user_stopped: bool,
|
pub user_stopped: bool,
|
||||||
pub service_status: Status,
|
pub service_status: Status,
|
||||||
pub sub_services: Vec<SubServiceData>,
|
pub sub_services: Vec<SubServiceData>,
|
||||||
|
/// Memory usage in bytes (from MemoryCurrent)
|
||||||
|
pub memory_bytes: Option<u64>,
|
||||||
|
/// Number of service restarts (from NRestarts)
|
||||||
|
pub restart_count: Option<u32>,
|
||||||
|
/// Uptime in seconds (calculated from ExecMainStartTimestamp)
|
||||||
|
pub uptime_seconds: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sub-service data (nginx sites, docker containers, etc.)
|
/// Sub-service data (nginx sites, docker containers, etc.)
|
||||||
@@ -198,7 +204,7 @@ impl AgentData {
|
|||||||
load_1min: 0.0,
|
load_1min: 0.0,
|
||||||
load_5min: 0.0,
|
load_5min: 0.0,
|
||||||
load_15min: 0.0,
|
load_15min: 0.0,
|
||||||
frequency_mhz: 0.0,
|
cstate: String::from("C0"),
|
||||||
temperature_celsius: None,
|
temperature_celsius: None,
|
||||||
load_status: Status::Unknown,
|
load_status: Status::Unknown,
|
||||||
temperature_status: Status::Unknown,
|
temperature_status: Status::Unknown,
|
||||||
|
|||||||
Reference in New Issue
Block a user