Update version to 0.1.21 and fix dashboard data caching
All checks were successful
Build and Release / build-and-release (push) Successful in 1m13s
All checks were successful
Build and Release / build-and-release (push) Successful in 1m13s
- Separate dashboard updates from email notifications for immediate status aggregation - Add metric caching to MetricCollectionManager for instant dashboard updates - Dashboard now receives cached data every 1 second instead of waiting for collection intervals - Fix transmission to use cached metrics rather than triggering fresh collection - Email notifications maintain separate 60-second batching interval - Update configurable email notification aggregation interval
This commit is contained in:
parent
a2519b2814
commit
43242debce
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.19"
|
||||
version = "0.1.20"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@ -291,7 +291,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.19"
|
||||
version = "0.1.20"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@ -314,7 +314,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.19"
|
||||
version = "0.1.20"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.20"
|
||||
version = "0.1.21"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@ -71,10 +71,11 @@ impl Agent {
|
||||
info!("Initial metric collection completed - all data cached and ready");
|
||||
}
|
||||
|
||||
// Separate intervals for collection and transmission
|
||||
// Separate intervals for collection, transmission, and email notifications
|
||||
let mut collection_interval =
|
||||
interval(Duration::from_secs(self.config.collection_interval_seconds));
|
||||
let mut transmission_interval = interval(Duration::from_secs(self.config.zmq.transmission_interval_seconds));
|
||||
let mut notification_interval = interval(Duration::from_secs(self.config.notifications.aggregation_interval_seconds));
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
@ -85,12 +86,13 @@ impl Agent {
|
||||
}
|
||||
}
|
||||
_ = transmission_interval.tick() => {
|
||||
// Send all metrics via ZMQ and process notifications immediately
|
||||
// Send all metrics via ZMQ (dashboard updates only)
|
||||
if let Err(e) = self.broadcast_all_metrics().await {
|
||||
error!("Failed to broadcast metrics: {}", e);
|
||||
}
|
||||
|
||||
// Process notifications immediately with each transmission
|
||||
}
|
||||
_ = notification_interval.tick() => {
|
||||
// Process batched email notifications (separate from dashboard updates)
|
||||
if let Err(e) = self.host_status_manager.process_pending_notifications(&mut self.notification_manager).await {
|
||||
error!("Failed to process pending notifications: {}", e);
|
||||
}
|
||||
@ -158,10 +160,10 @@ impl Agent {
|
||||
}
|
||||
|
||||
async fn broadcast_all_metrics(&mut self) -> Result<()> {
|
||||
debug!("Broadcasting all metrics via ZMQ");
|
||||
debug!("Broadcasting cached metrics via ZMQ");
|
||||
|
||||
// Get all current metrics from collectors
|
||||
let mut metrics = self.metric_manager.collect_all_metrics().await?;
|
||||
// Get cached metrics (no fresh collection)
|
||||
let mut metrics = self.metric_manager.get_cached_metrics();
|
||||
|
||||
// Add the host status summary metric from status manager
|
||||
let host_status_metric = self.host_status_manager.get_host_status_metric();
|
||||
@ -176,7 +178,7 @@ impl Agent {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
debug!("Broadcasting {} metrics (including host status summary)", metrics.len());
|
||||
debug!("Broadcasting {} cached metrics (including host status summary)", metrics.len());
|
||||
|
||||
// Create and send message with all current data
|
||||
let message = MetricMessage::new(self.hostname.clone(), metrics);
|
||||
|
||||
@ -143,6 +143,8 @@ pub struct NotificationConfig {
|
||||
pub from_email: String,
|
||||
pub to_email: String,
|
||||
pub rate_limit_minutes: u64,
|
||||
/// Email notification batching interval in seconds (default: 60)
|
||||
pub aggregation_interval_seconds: u64,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ struct TimedCollector {
|
||||
pub struct MetricCollectionManager {
|
||||
collectors: Vec<TimedCollector>,
|
||||
status_tracker: StatusTracker,
|
||||
cached_metrics: Vec<Metric>,
|
||||
}
|
||||
|
||||
impl MetricCollectionManager {
|
||||
@ -177,6 +178,7 @@ impl MetricCollectionManager {
|
||||
Ok(Self {
|
||||
collectors,
|
||||
status_tracker: StatusTracker::new(),
|
||||
cached_metrics: Vec::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -198,6 +200,9 @@ impl MetricCollectionManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cache the collected metrics
|
||||
self.cached_metrics = all_metrics.clone();
|
||||
Ok(all_metrics)
|
||||
}
|
||||
|
||||
@ -231,6 +236,18 @@ impl MetricCollectionManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update cache with newly collected metrics
|
||||
if !all_metrics.is_empty() {
|
||||
// Merge new metrics with cached metrics (replace by name)
|
||||
for new_metric in &all_metrics {
|
||||
// Remove any existing metric with the same name
|
||||
self.cached_metrics.retain(|cached| cached.name != new_metric.name);
|
||||
// Add the new metric
|
||||
self.cached_metrics.push(new_metric.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(all_metrics)
|
||||
}
|
||||
|
||||
@ -238,5 +255,10 @@ impl MetricCollectionManager {
|
||||
pub async fn collect_all_metrics(&mut self) -> Result<Vec<Metric>> {
|
||||
self.collect_metrics_timed().await
|
||||
}
|
||||
|
||||
/// Get cached metrics without triggering fresh collection
|
||||
pub fn get_cached_metrics(&self) -> Vec<Metric> {
|
||||
self.cached_metrics.clone()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.20"
|
||||
version = "0.1.21"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@ -14,7 +14,7 @@ use app::Dashboard;
|
||||
|
||||
/// Get hardcoded version
|
||||
fn get_version() -> &'static str {
|
||||
"v0.1.20"
|
||||
"v0.1.21"
|
||||
}
|
||||
|
||||
/// Check if running inside tmux session
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.20"
|
||||
version = "0.1.21"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user