Clean up unused imports and fix build warnings

- Remove unused imports (Duration, HashMap, SharedError, DateTime, etc.)
- Fix unused variables by prefixing with underscore
- Remove redundant dashboard.toml config file
- Update theme imports to use only needed components
- Maintain all functionality while reducing warnings
- Add srv02 to predefined hosts configuration
- Remove unused broadcast_command methods
This commit is contained in:
Christoffer Martinsson 2025-10-18 23:12:07 +02:00
parent f0eec38655
commit 7f85a6436e
21 changed files with 27 additions and 150 deletions

View File

@ -1,8 +1,7 @@
use super::ConfigurableCache;
use cm_dashboard_shared::{CacheConfig, Metric};
use std::sync::Arc;
use tokio::time::{interval, Duration};
use tracing::{debug, info};
use tracing::info;
/// Manages metric caching with background tasks
pub struct MetricCacheManager {

View File

@ -2,7 +2,7 @@ use cm_dashboard_shared::{CacheConfig, Metric};
use std::collections::HashMap;
use std::time::Instant;
use tokio::sync::RwLock;
use tracing::{debug, warn};
use tracing::warn;
mod manager;
mod cached_metric;
@ -167,7 +167,7 @@ impl ConfigurableCache {
let cache = self.cache.read().await;
let mut stats_by_tier = HashMap::new();
for (metric_name, cached_metric) in cache.iter() {
for (_metric_name, cached_metric) in cache.iter() {
let tier_name = cached_metric.tier
.as_ref()
.map(|t| t.description.clone())

View File

@ -1,12 +1,11 @@
use async_trait::async_trait;
use cm_dashboard_shared::{Metric, MetricValue, Status, SharedError};
use chrono::{DateTime, Utc};
use cm_dashboard_shared::{Metric, MetricValue, Status};
use chrono::Utc;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::Path;
use tokio::fs;
use super::{Collector, CollectorError, utils};
use super::{Collector, CollectorError};
use tracing::error;
/// Backup collector that reads TOML status files for borgbackup metrics

View File

@ -1,6 +1,6 @@
use async_trait::async_trait;
use cm_dashboard_shared::{Metric, MetricValue, Status, registry};
use std::time::Duration;
use tracing::debug;
use super::{Collector, CollectorError, utils};

View File

@ -1,7 +1,7 @@
use anyhow::Result;
use async_trait::async_trait;
use cm_dashboard_shared::{Metric, MetricValue, Status};
use std::collections::HashMap;
use std::process::Command;
use std::time::Instant;
use tracing::debug;
@ -398,7 +398,7 @@ impl Collector for DiskCollector {
}
// Add SMART health metrics for each unique physical device
for (physical_device, disks) in physical_devices {
for (physical_device, _disks) in physical_devices {
let (health_status, temperature) = self.get_smart_health(&physical_device);
let device_name = physical_device.strip_prefix("/dev/").unwrap_or(&physical_device);
let timestamp = chrono::Utc::now().timestamp() as u64;

View File

@ -1,6 +1,6 @@
use async_trait::async_trait;
use cm_dashboard_shared::{Metric, MetricValue, Status, registry};
use std::time::Duration;
use tracing::debug;
use super::{Collector, CollectorError, utils};

View File

@ -1,5 +1,5 @@
use async_trait::async_trait;
use cm_dashboard_shared::{Metric, SharedError};
use cm_dashboard_shared::Metric;
use std::time::Duration;
pub mod cached_collector;

View File

@ -1,6 +1,6 @@
use anyhow::Result;
use cm_dashboard_shared::{MetricMessage, MessageEnvelope};
use tracing::{info, error, debug};
use tracing::{info, debug};
use zmq::{Context, Socket, SocketType};
use crate::config::ZmqConfig;

View File

@ -5,7 +5,7 @@ use std::time::Instant;
use tracing::{info, error, debug};
use crate::config::{CollectorConfig, AgentConfig};
use crate::collectors::{Collector, cpu::CpuCollector, memory::MemoryCollector, disk::DiskCollector, systemd::SystemdCollector, backup::BackupCollector, cached_collector::CachedCollector};
use crate::collectors::{Collector, cpu::CpuCollector, memory::MemoryCollector, disk::DiskCollector, systemd::SystemdCollector, backup::BackupCollector};
use crate::cache::MetricCacheManager;
/// Manages all metric collectors with intelligent caching
@ -195,7 +195,7 @@ impl MetricCollectionManager {
}
}
} else {
let elapsed = self.last_collection_times.get(collector_name)
let _elapsed = self.last_collection_times.get(collector_name)
.map(|t| now.duration_since(*t).as_secs())
.unwrap_or(0);
// Collector skipped (debug logging disabled for performance)

View File

@ -1,7 +1,7 @@
use cm_dashboard_shared::Status;
use std::collections::HashMap;
use std::time::Instant;
use tracing::{info, debug, warn};
use tracing::{info, debug};
use crate::config::NotificationConfig;

View File

@ -1,41 +0,0 @@
# CM Dashboard configuration
[hosts]
# default_host = "srv01"
[[hosts.hosts]]
name = "srv01"
enabled = true
# metadata = { rack = "R1" }
[[hosts.hosts]]
name = "labbox"
enabled = true
[[hosts.hosts]]
name = "srv02"
enabled = true
[dashboard]
tick_rate_ms = 250
history_duration_minutes = 60
[[dashboard.widgets]]
id = "nvme"
enabled = true
[[dashboard.widgets]]
id = "services"
enabled = true
[[dashboard.widgets]]
id = "backup"
enabled = true
[[dashboard.widgets]]
id = "alerts"
enabled = true
[filesystem]
# cache_dir = "/var/lib/cm-dashboard/cache"
# history_dir = "/var/lib/cm-dashboard/history"

View File

@ -57,20 +57,8 @@ impl Dashboard {
}
};
// Connect to predefined hosts
let hosts = if config.hosts.predefined_hosts.is_empty() {
vec![
"localhost".to_string(),
"cmbox".to_string(),
"labbox".to_string(),
"simonbox".to_string(),
"steambox".to_string(),
"srv01".to_string(),
"srv02".to_string(),
]
} else {
config.hosts.predefined_hosts.clone()
};
// Connect to predefined hosts from configuration
let hosts = config.hosts.predefined_hosts.clone();
// Try to connect to hosts but don't fail if none are available
match zmq_consumer.connect_to_predefined_hosts(&hosts).await {
@ -139,11 +127,6 @@ impl Dashboard {
self.zmq_command_sender.send_command(hostname, command).await
}
/// Send a command to all connected hosts
pub async fn broadcast_command(&mut self, command: AgentCommand) -> Result<Vec<String>> {
let connected_hosts = self.metric_store.get_connected_hosts(Duration::from_secs(30));
self.zmq_command_sender.broadcast_command(&connected_hosts, command).await
}
pub async fn run(&mut self) -> Result<()> {
info!("Starting dashboard main loop");

View File

@ -2,7 +2,6 @@ use anyhow::Result;
use cm_dashboard_shared::{MetricMessage, MessageEnvelope, MessageType};
use tracing::{info, error, debug, warn};
use zmq::{Context, Socket, SocketType};
use std::time::Duration;
use crate::config::ZmqConfig;
@ -80,11 +79,6 @@ impl ZmqConsumer {
Ok(())
}
/// Get list of newly connected hosts since last check
pub fn get_newly_connected_hosts(&self) -> Vec<String> {
// For now, return all connected hosts (could be enhanced with state tracking)
self.connected_hosts.iter().cloned().collect()
}
/// Receive metrics from any connected agent (non-blocking)
pub async fn receive_metrics(&mut self) -> Result<Option<MetricMessage>> {
@ -128,32 +122,21 @@ impl ZmqConsumer {
}
}
/// Get list of connected hosts
pub fn get_connected_hosts(&self) -> Vec<String> {
self.connected_hosts.iter().cloned().collect()
}
/// Check if connected to any hosts
pub fn has_connections(&self) -> bool {
!self.connected_hosts.is_empty()
}
}
/// ZMQ command sender for sending commands to agents
pub struct ZmqCommandSender {
context: Context,
config: ZmqConfig,
}
impl ZmqCommandSender {
pub fn new(config: &ZmqConfig) -> Result<Self> {
pub fn new(_config: &ZmqConfig) -> Result<Self> {
let context = Context::new();
info!("ZMQ command sender initialized");
Ok(Self {
context,
config: config.clone(),
})
}
@ -181,24 +164,4 @@ impl ZmqCommandSender {
// Socket will be automatically closed when dropped
Ok(())
}
/// Send a command to all connected hosts
pub async fn broadcast_command(&self, hosts: &[String], command: AgentCommand) -> Result<Vec<String>> {
let mut failed_hosts = Vec::new();
for hostname in hosts {
if let Err(e) = self.send_command(hostname, command.clone()).await {
error!("Failed to send command to {}: {}", hostname, e);
failed_hosts.push(hostname.clone());
}
}
if failed_hosts.is_empty() {
info!("Successfully broadcast command {:?} to {} hosts", command, hosts.len());
} else {
warn!("Failed to send command to {} hosts: {:?}", failed_hosts.len(), failed_hosts);
}
Ok(failed_hosts)
}
}

View File

@ -111,6 +111,7 @@ impl Default for HostsConfig {
"simonbox".to_string(),
"steambox".to_string(),
"srv01".to_string(),
"srv02".to_string(),
],
default_host: Some("cmbox".to_string()),
}

View File

@ -1,13 +1,10 @@
use cm_dashboard_shared::{Metric, Status};
use std::collections::HashMap;
use std::time::{Duration, Instant};
use tracing::{debug, info};
use std::time::Instant;
pub mod store;
pub mod subscription;
pub use store::MetricStore;
pub use subscription::SubscriptionManager;
/// Widget types that can subscribe to metrics
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
@ -21,13 +18,6 @@ pub enum WidgetType {
Alerts,
}
/// Metric subscription entry
#[derive(Debug, Clone)]
pub struct MetricSubscription {
pub widget_type: WidgetType,
pub metric_names: Vec<String>,
}
/// Historical metric data point
#[derive(Debug, Clone)]
pub struct MetricDataPoint {

View File

@ -1,7 +1,7 @@
use std::collections::{HashMap, HashSet};
use tracing::{debug, info};
use super::{WidgetType, MetricSubscription, subscriptions};
use super::{WidgetType, subscriptions};
/// Manages metric subscriptions for widgets
pub struct SubscriptionManager {
@ -41,23 +41,6 @@ impl SubscriptionManager {
subscriptions::MEMORY_WIDGET_METRICS.iter().map(|&s| s.to_string()).collect()
);
// Subscribe Storage widget to storage metrics
self.subscribe_widget(
WidgetType::Storage,
subscriptions::STORAGE_WIDGET_METRICS.iter().map(|&s| s.to_string()).collect()
);
// Subscribe Services widget to service metrics
self.subscribe_widget(
WidgetType::Services,
subscriptions::SERVICES_WIDGET_METRICS.iter().map(|&s| s.to_string()).collect()
);
// Subscribe Backup widget to backup metrics
self.subscribe_widget(
WidgetType::Backup,
subscriptions::BACKUP_WIDGET_METRICS.iter().map(|&s| s.to_string()).collect()
);
info!("Initialized default widget subscriptions for {} widgets",
self.widget_subscriptions.len());

View File

@ -330,9 +330,9 @@ impl TuiApp {
}
// Calculate how many lines we need
let mut total_lines_needed = 0;
let mut _total_lines_needed = 0;
for partitions in physical_devices.values() {
total_lines_needed += 2 + partitions.len(); // title + health + usage_per_partition
_total_lines_needed += 2 + partitions.len(); // title + health + usage_per_partition
}
let available_lines = area.height as usize;

View File

@ -7,7 +7,7 @@ use ratatui::{
use tracing::debug;
use super::Widget;
use crate::ui::theme::{Theme, Typography, Components, StatusIcons};
use crate::ui::theme::{Typography, StatusIcons};
/// Backup widget displaying backup status, services, and repository information
#[derive(Clone)]

View File

@ -7,7 +7,7 @@ use ratatui::{
use tracing::debug;
use super::Widget;
use crate::ui::theme::{Theme, Typography, Components, StatusIcons};
use crate::ui::theme::{Typography, StatusIcons};
/// CPU widget displaying load, temperature, and frequency
#[derive(Clone)]

View File

@ -7,7 +7,7 @@ use ratatui::{
use tracing::debug;
use super::Widget;
use crate::ui::theme::{Theme, Typography, Components, StatusIcons};
use crate::ui::theme::{Typography, StatusIcons};
/// Memory widget displaying usage, totals, and swap information
#[derive(Clone)]

View File

@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use chrono::{DateTime, Utc};
use chrono::Utc;
/// Individual metric with value, status, and metadata
#[derive(Debug, Clone, Serialize, Deserialize)]