Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bdfff942f7 | |||
| 47ab1e387d | |||
| 966ba27b1e | |||
| 6c6c9144bd | |||
| 3fdcec8047 | |||
| 1fcaf4a670 | |||
| 885e19f7fd | |||
| a7b69b8ae7 |
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.230"
|
version = "0.1.238"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.230"
|
version = "0.1.238"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -325,7 +325,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.230"
|
version = "0.1.238"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.230"
|
version = "0.1.238"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ impl DiskCollector {
|
|||||||
|
|
||||||
/// Collect all storage data and populate AgentData
|
/// Collect all storage data and populate AgentData
|
||||||
async fn collect_storage_data(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
async fn collect_storage_data(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||||
|
// Clear drives and pools to prevent duplicates when updating cached data
|
||||||
|
agent_data.system.storage.drives.clear();
|
||||||
|
agent_data.system.storage.pools.clear();
|
||||||
|
|
||||||
// Step 1: Get mount points and their backing devices
|
// Step 1: Get mount points and their backing devices
|
||||||
let mount_devices = self.get_mount_devices().await?;
|
let mount_devices = self.get_mount_devices().await?;
|
||||||
|
|
||||||
|
|||||||
@@ -200,13 +200,16 @@ impl Collector for MemoryCollector {
|
|||||||
debug!("Collecting memory metrics");
|
debug!("Collecting memory metrics");
|
||||||
let start = std::time::Instant::now();
|
let start = std::time::Instant::now();
|
||||||
|
|
||||||
|
// Clear tmpfs list to prevent duplicates when updating cached data
|
||||||
|
agent_data.system.memory.tmpfs.clear();
|
||||||
|
|
||||||
// Parse memory info from /proc/meminfo
|
// Parse memory info from /proc/meminfo
|
||||||
let info = self.parse_meminfo().await?;
|
let info = self.parse_meminfo().await?;
|
||||||
|
|
||||||
// Populate memory data directly
|
// Populate memory data directly
|
||||||
self.populate_memory_data(&info, agent_data).await?;
|
self.populate_memory_data(&info, agent_data).await?;
|
||||||
|
|
||||||
// Collect tmpfs data
|
// Collect tmpfs data
|
||||||
self.populate_tmpfs_data(agent_data).await?;
|
self.populate_tmpfs_data(agent_data).await?;
|
||||||
|
|
||||||
let duration = start.elapsed();
|
let duration = start.elapsed();
|
||||||
|
|||||||
@@ -159,6 +159,19 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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::Info,
|
||||||
|
metrics,
|
||||||
|
service_type: "vpn_route".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create complete service data
|
// Create complete service data
|
||||||
let service_data = ServiceData {
|
let service_data = ServiceData {
|
||||||
name: service_name.clone(),
|
name: service_name.clone(),
|
||||||
@@ -836,11 +849,43 @@ impl SystemdCollector {
|
|||||||
_ => value, // Assume bytes if no unit
|
_ => value, // Assume bytes if no unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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",
|
||||||
|
"vpn",
|
||||||
|
"curl",
|
||||||
|
"-s",
|
||||||
|
"--max-time",
|
||||||
|
"4",
|
||||||
|
"https://ifconfig.me"
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
|
if output.status.success() {
|
||||||
|
let ip = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||||
|
if !ip.is_empty() && ip.contains('.') {
|
||||||
|
return Some(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Collector for SystemdCollector {
|
impl Collector for SystemdCollector {
|
||||||
async fn collect_structured(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
async fn collect_structured(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||||
|
// Clear services to prevent duplicates when updating cached data
|
||||||
|
agent_data.services.clear();
|
||||||
|
|
||||||
// Use cached complete data if available and fresh
|
// Use cached complete data if available and fresh
|
||||||
if let Some(cached_complete_services) = self.get_cached_complete_services() {
|
if let Some(cached_complete_services) = self.get_cached_complete_services() {
|
||||||
for service_data in cached_complete_services {
|
for service_data in cached_complete_services {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.230"
|
version = "0.1.238"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ impl Theme {
|
|||||||
/// Get color for status level
|
/// Get color for status level
|
||||||
pub fn status_color(status: Status) -> Color {
|
pub fn status_color(status: Status) -> Color {
|
||||||
match status {
|
match status {
|
||||||
|
Status::Info => Self::muted_text(), // Gray for informational data
|
||||||
Status::Ok => Self::success(),
|
Status::Ok => Self::success(),
|
||||||
Status::Inactive => Self::muted_text(), // Gray for inactive services in service list
|
Status::Inactive => Self::muted_text(), // Gray for inactive services in service list
|
||||||
Status::Pending => Self::highlight(), // Blue for pending
|
Status::Pending => Self::highlight(), // Blue for pending
|
||||||
@@ -240,6 +241,7 @@ impl StatusIcons {
|
|||||||
/// Get status icon symbol
|
/// Get status icon symbol
|
||||||
pub fn get_icon(status: Status) -> &'static str {
|
pub fn get_icon(status: Status) -> &'static str {
|
||||||
match status {
|
match status {
|
||||||
|
Status::Info => "", // No icon for informational data
|
||||||
Status::Ok => "●",
|
Status::Ok => "●",
|
||||||
Status::Inactive => "○", // Empty circle for inactive services
|
Status::Inactive => "○", // Empty circle for inactive services
|
||||||
Status::Pending => "◉", // Hollow circle for pending
|
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>> {
|
pub fn create_status_spans(status: Status, text: &str) -> Vec<ratatui::text::Span<'static>> {
|
||||||
let icon = Self::get_icon(status);
|
let icon = Self::get_icon(status);
|
||||||
let status_color = match status {
|
let status_color = match status {
|
||||||
|
Status::Info => Theme::muted_text(), // Gray for info
|
||||||
Status::Ok => Theme::success(), // Green
|
Status::Ok => Theme::success(), // Green
|
||||||
Status::Inactive => Theme::muted_text(), // Gray for inactive services
|
Status::Inactive => Theme::muted_text(), // Gray for inactive services
|
||||||
Status::Pending => Theme::highlight(), // Blue
|
Status::Pending => Theme::highlight(), // Blue
|
||||||
|
|||||||
@@ -156,6 +156,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::Info => "", // Shouldn't happen for parent services
|
||||||
Status::Ok => "active",
|
Status::Ok => "active",
|
||||||
Status::Inactive => "inactive",
|
Status::Inactive => "inactive",
|
||||||
Status::Critical => "failed",
|
Status::Critical => "failed",
|
||||||
@@ -239,6 +240,7 @@ impl ServicesWidget {
|
|||||||
// Get status icon and text
|
// Get status icon and text
|
||||||
let icon = StatusIcons::get_icon(info.widget_status);
|
let icon = StatusIcons::get_icon(info.widget_status);
|
||||||
let status_color = match info.widget_status {
|
let status_color = match info.widget_status {
|
||||||
|
Status::Info => Theme::muted_text(),
|
||||||
Status::Ok => Theme::success(),
|
Status::Ok => Theme::success(),
|
||||||
Status::Inactive => Theme::muted_text(),
|
Status::Inactive => Theme::muted_text(),
|
||||||
Status::Pending => Theme::highlight(),
|
Status::Pending => Theme::highlight(),
|
||||||
@@ -259,6 +261,7 @@ impl ServicesWidget {
|
|||||||
} else {
|
} else {
|
||||||
// Convert Status enum to display text for sub-services
|
// Convert Status enum to display text for sub-services
|
||||||
match info.widget_status {
|
match info.widget_status {
|
||||||
|
Status::Info => "",
|
||||||
Status::Ok => "active",
|
Status::Ok => "active",
|
||||||
Status::Inactive => "inactive",
|
Status::Inactive => "inactive",
|
||||||
Status::Critical => "failed",
|
Status::Critical => "failed",
|
||||||
@@ -298,6 +301,22 @@ impl ServicesWidget {
|
|||||||
.bg(Theme::background()),
|
.bg(Theme::background()),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
} else if info.widget_status == Status::Info {
|
||||||
|
// Informational data - no status icon
|
||||||
|
vec![
|
||||||
|
// Indentation and tree prefix
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
format!(" {} ", tree_symbol),
|
||||||
|
Typography::tree(),
|
||||||
|
),
|
||||||
|
// Service name (no icon)
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
short_name,
|
||||||
|
Style::default()
|
||||||
|
.fg(Theme::secondary_text())
|
||||||
|
.bg(Theme::background()),
|
||||||
|
),
|
||||||
|
]
|
||||||
} else {
|
} else {
|
||||||
vec![
|
vec![
|
||||||
// Indentation and tree prefix
|
// Indentation and tree prefix
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.230"
|
version = "0.1.238"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -82,12 +82,13 @@ impl MetricValue {
|
|||||||
/// Health status for metrics
|
/// Health status for metrics
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
Inactive, // Lowest priority
|
Info, // Lowest priority - informational data with no status (no icon)
|
||||||
Unknown, //
|
Inactive, //
|
||||||
Offline, //
|
Unknown, //
|
||||||
Pending, //
|
Offline, //
|
||||||
Ok, // 5th place - good status has higher priority than unknown states
|
Pending, //
|
||||||
Warning, //
|
Ok, // Good status has higher priority than unknown states
|
||||||
|
Warning, //
|
||||||
Critical, // Highest priority
|
Critical, // Highest priority
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +224,17 @@ impl HysteresisThresholds {
|
|||||||
Status::Ok
|
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