Remove unused code and eliminate build warnings

Removed unused widget subscription system, cache utilities, error variants,
theme functions, and struct fields. Replaced subscription-based widgets
with direct metric filtering. Build now completes with zero warnings.
This commit is contained in:
2025-10-18 23:50:15 +02:00
parent 7f85a6436e
commit 0141a6e111
14 changed files with 15 additions and 764 deletions

View File

@@ -1,9 +1,9 @@
use cm_dashboard_shared::{Metric, Status};
use cm_dashboard_shared::Metric;
use std::collections::HashMap;
use std::time::{Duration, Instant};
use tracing::{debug, info, warn};
use super::{MetricDataPoint, WidgetType, subscriptions};
use super::MetricDataPoint;
/// Central metric storage for the dashboard
pub struct MetricStore {
@@ -54,7 +54,6 @@ impl MetricStore {
// Add to history
host_history.push(MetricDataPoint {
metric,
received_at: now,
});
}
@@ -80,6 +79,7 @@ impl MetricStore {
}
/// Get all current metrics for a host
#[allow(dead_code)]
pub fn get_host_metrics(&self, hostname: &str) -> Option<&HashMap<String, Metric>> {
self.current_metrics.get(hostname)
}
@@ -93,36 +93,7 @@ impl MetricStore {
}
}
/// Get metrics for a specific widget type
pub fn get_metrics_for_widget(&self, hostname: &str, widget_type: WidgetType) -> Vec<&Metric> {
let subscriptions = subscriptions::get_widget_subscriptions(widget_type);
if let Some(host_metrics) = self.get_host_metrics(hostname) {
subscriptions
.iter()
.filter_map(|&metric_name| host_metrics.get(metric_name))
.collect()
} else {
Vec::new()
}
}
/// Get aggregated status for a widget
pub fn get_widget_status(&self, hostname: &str, widget_type: WidgetType) -> Status {
let metrics = self.get_metrics_for_widget(hostname, widget_type);
if metrics.is_empty() {
Status::Unknown
} else {
let statuses: Vec<Status> = metrics.iter().map(|m| m.status).collect();
Status::aggregate(&statuses)
}
}
/// Get list of all hosts with metrics
pub fn get_hosts(&self) -> Vec<String> {
self.current_metrics.keys().cloned().collect()
}
/// Get connected hosts (hosts with recent updates)
pub fn get_connected_hosts(&self, timeout: Duration) -> Vec<String> {
@@ -140,45 +111,7 @@ impl MetricStore {
.collect()
}
/// Get last update timestamp for a host
pub fn get_last_update(&self, hostname: &str) -> Option<Instant> {
self.last_update.get(hostname).copied()
}
/// Check if host is considered connected
pub fn is_host_connected(&self, hostname: &str, timeout: Duration) -> bool {
if let Some(&last_update) = self.last_update.get(hostname) {
Instant::now().duration_since(last_update) <= timeout
} else {
false
}
}
/// Get metric value as specific type (helper function)
pub fn get_metric_value_f32(&self, hostname: &str, metric_name: &str) -> Option<f32> {
self.get_metric(hostname, metric_name)?
.value
.as_f32()
}
/// Get metric value as string (helper function)
pub fn get_metric_value_string(&self, hostname: &str, metric_name: &str) -> Option<String> {
Some(self.get_metric(hostname, metric_name)?
.value
.as_string())
}
/// Get historical data for a metric
pub fn get_metric_history(&self, hostname: &str, metric_name: &str) -> Vec<&MetricDataPoint> {
if let Some(history) = self.historical_metrics.get(hostname) {
history
.iter()
.filter(|dp| dp.metric.name == metric_name)
.collect()
} else {
Vec::new()
}
}
/// Cleanup old data and enforce limits
fn cleanup_host_data(&mut self, hostname: &str) {
@@ -199,32 +132,4 @@ impl MetricStore {
}
}
/// Get storage statistics
pub fn get_stats(&self) -> MetricStoreStats {
let total_current_metrics: usize = self.current_metrics
.values()
.map(|host_metrics| host_metrics.len())
.sum();
let total_historical_metrics: usize = self.historical_metrics
.values()
.map(|history| history.len())
.sum();
MetricStoreStats {
total_hosts: self.current_metrics.len(),
total_current_metrics,
total_historical_metrics,
connected_hosts: self.get_connected_hosts(Duration::from_secs(30)).len(),
}
}
}
/// Metric store statistics
#[derive(Debug, Clone)]
pub struct MetricStoreStats {
pub total_hosts: usize,
pub total_current_metrics: usize,
pub total_historical_metrics: usize,
pub connected_hosts: usize,
}