Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 966ba27b1e | |||
| 6c6c9144bd | |||
| 3fdcec8047 | |||
| 1fcaf4a670 | |||
| 885e19f7fd | |||
| a7b69b8ae7 | |||
| 2d290f40b2 |
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.229"
|
version = "0.1.236"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.229"
|
version = "0.1.236"
|
||||||
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.229"
|
version = "0.1.236"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.229"
|
version = "0.1.236"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ pub struct Agent {
|
|||||||
collectors: Vec<TimedCollector>,
|
collectors: Vec<TimedCollector>,
|
||||||
notification_manager: NotificationManager,
|
notification_manager: NotificationManager,
|
||||||
previous_status: Option<SystemStatus>,
|
previous_status: Option<SystemStatus>,
|
||||||
|
cached_agent_data: AgentData,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Track system component status for change detection
|
/// Track system component status for change detection
|
||||||
@@ -143,6 +144,9 @@ impl Agent {
|
|||||||
let notification_manager = NotificationManager::new(&config.notifications, &hostname)?;
|
let notification_manager = NotificationManager::new(&config.notifications, &hostname)?;
|
||||||
info!("Notification manager initialized");
|
info!("Notification manager initialized");
|
||||||
|
|
||||||
|
// Initialize cached agent data
|
||||||
|
let cached_agent_data = AgentData::new(hostname.clone(), env!("CARGO_PKG_VERSION").to_string());
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
hostname,
|
hostname,
|
||||||
config,
|
config,
|
||||||
@@ -150,6 +154,7 @@ impl Agent {
|
|||||||
collectors,
|
collectors,
|
||||||
notification_manager,
|
notification_manager,
|
||||||
previous_status: None,
|
previous_status: None,
|
||||||
|
cached_agent_data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,10 +204,8 @@ impl Agent {
|
|||||||
async fn collect_and_broadcast(&mut self) -> Result<()> {
|
async fn collect_and_broadcast(&mut self) -> Result<()> {
|
||||||
debug!("Starting structured data collection");
|
debug!("Starting structured data collection");
|
||||||
|
|
||||||
// Initialize empty AgentData
|
|
||||||
let mut agent_data = AgentData::new(self.hostname.clone(), env!("CARGO_PKG_VERSION").to_string());
|
|
||||||
|
|
||||||
// Collect data from collectors whose intervals have elapsed
|
// Collect data from collectors whose intervals have elapsed
|
||||||
|
// Update cached_agent_data with new data
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
for timed_collector in &mut self.collectors {
|
for timed_collector in &mut self.collectors {
|
||||||
let should_collect = match timed_collector.last_collection {
|
let should_collect = match timed_collector.last_collection {
|
||||||
@@ -211,7 +214,7 @@ impl Agent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if should_collect {
|
if should_collect {
|
||||||
if let Err(e) = timed_collector.collector.collect_structured(&mut agent_data).await {
|
if let Err(e) = timed_collector.collector.collect_structured(&mut self.cached_agent_data).await {
|
||||||
error!("Collector {} failed: {}", timed_collector.name, e);
|
error!("Collector {} failed: {}", timed_collector.name, e);
|
||||||
// Update last_collection time even on failure to prevent immediate retries
|
// Update last_collection time even on failure to prevent immediate retries
|
||||||
timed_collector.last_collection = Some(now);
|
timed_collector.last_collection = Some(now);
|
||||||
@@ -226,13 +229,22 @@ impl Agent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update timestamp on cached data
|
||||||
|
self.cached_agent_data.timestamp = std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs();
|
||||||
|
|
||||||
|
// Clone for notification check (to avoid borrow issues)
|
||||||
|
let agent_data_snapshot = self.cached_agent_data.clone();
|
||||||
|
|
||||||
// Check for status changes and send notifications
|
// Check for status changes and send notifications
|
||||||
if let Err(e) = self.check_status_changes_and_notify(&agent_data).await {
|
if let Err(e) = self.check_status_changes_and_notify(&agent_data_snapshot).await {
|
||||||
error!("Failed to check status changes: {}", e);
|
error!("Failed to check status changes: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast the structured data via ZMQ
|
// Broadcast the cached structured data via ZMQ
|
||||||
if let Err(e) = self.zmq_handler.publish_agent_data(&agent_data).await {
|
if let Err(e) = self.zmq_handler.publish_agent_data(&agent_data_snapshot).await {
|
||||||
error!("Failed to broadcast agent data: {}", e);
|
error!("Failed to broadcast agent data: {}", e);
|
||||||
} else {
|
} else {
|
||||||
debug!("Successfully broadcast structured agent data");
|
debug!("Successfully broadcast structured agent data");
|
||||||
|
|||||||
@@ -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,6 +200,9 @@ 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?;
|
||||||
|
|
||||||
|
|||||||
@@ -159,6 +159,26 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if service_name == "openvpn-vpn-connection" && status_info.active_state == "active" {
|
||||||
|
tracing::info!("Checking VPN external IP for service: {}", service_name);
|
||||||
|
match self.get_vpn_external_ip() {
|
||||||
|
Some(external_ip) => {
|
||||||
|
tracing::info!("Got VPN external IP: {}", external_ip);
|
||||||
|
let metrics = Vec::new();
|
||||||
|
|
||||||
|
sub_services.push(SubServiceData {
|
||||||
|
name: format!("ip: {}", external_ip),
|
||||||
|
service_status: Status::Ok,
|
||||||
|
metrics,
|
||||||
|
service_type: "vpn_route".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
tracing::warn!("Failed to get VPN external IP");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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 +856,45 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
|
tracing::warn!("VPN external IP query failed. Exit code: {:?}, stderr: {}", output.status.code(), stderr);
|
||||||
|
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.229"
|
version = "0.1.236"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -298,6 +298,22 @@ impl ServicesWidget {
|
|||||||
.bg(Theme::background()),
|
.bg(Theme::background()),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
} else if info.service_type == "vpn_route" {
|
||||||
|
// VPN route info - 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.229"
|
version = "0.1.236"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Reference in New Issue
Block a user