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:
parent
f0eec38655
commit
7f85a6436e
3
agent/src/cache/manager.rs
vendored
3
agent/src/cache/manager.rs
vendored
@ -1,8 +1,7 @@
|
|||||||
use super::ConfigurableCache;
|
use super::ConfigurableCache;
|
||||||
use cm_dashboard_shared::{CacheConfig, Metric};
|
use cm_dashboard_shared::{CacheConfig, Metric};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::time::{interval, Duration};
|
use tracing::info;
|
||||||
use tracing::{debug, info};
|
|
||||||
|
|
||||||
/// Manages metric caching with background tasks
|
/// Manages metric caching with background tasks
|
||||||
pub struct MetricCacheManager {
|
pub struct MetricCacheManager {
|
||||||
|
|||||||
4
agent/src/cache/mod.rs
vendored
4
agent/src/cache/mod.rs
vendored
@ -2,7 +2,7 @@ use cm_dashboard_shared::{CacheConfig, Metric};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tracing::{debug, warn};
|
use tracing::warn;
|
||||||
|
|
||||||
mod manager;
|
mod manager;
|
||||||
mod cached_metric;
|
mod cached_metric;
|
||||||
@ -167,7 +167,7 @@ impl ConfigurableCache {
|
|||||||
let cache = self.cache.read().await;
|
let cache = self.cache.read().await;
|
||||||
|
|
||||||
let mut stats_by_tier = HashMap::new();
|
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
|
let tier_name = cached_metric.tier
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|t| t.description.clone())
|
.map(|t| t.description.clone())
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cm_dashboard_shared::{Metric, MetricValue, Status, SharedError};
|
use cm_dashboard_shared::{Metric, MetricValue, Status};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::Utc;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
use super::{Collector, CollectorError, utils};
|
use super::{Collector, CollectorError};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
/// Backup collector that reads TOML status files for borgbackup metrics
|
/// Backup collector that reads TOML status files for borgbackup metrics
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cm_dashboard_shared::{Metric, MetricValue, Status, registry};
|
use cm_dashboard_shared::{Metric, MetricValue, Status, registry};
|
||||||
use std::time::Duration;
|
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use super::{Collector, CollectorError, utils};
|
use super::{Collector, CollectorError, utils};
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cm_dashboard_shared::{Metric, MetricValue, Status};
|
use cm_dashboard_shared::{Metric, MetricValue, Status};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
@ -398,7 +398,7 @@ impl Collector for DiskCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add SMART health metrics for each unique physical device
|
// 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 (health_status, temperature) = self.get_smart_health(&physical_device);
|
||||||
let device_name = physical_device.strip_prefix("/dev/").unwrap_or(&physical_device);
|
let device_name = physical_device.strip_prefix("/dev/").unwrap_or(&physical_device);
|
||||||
let timestamp = chrono::Utc::now().timestamp() as u64;
|
let timestamp = chrono::Utc::now().timestamp() as u64;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cm_dashboard_shared::{Metric, MetricValue, Status, registry};
|
use cm_dashboard_shared::{Metric, MetricValue, Status, registry};
|
||||||
use std::time::Duration;
|
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use super::{Collector, CollectorError, utils};
|
use super::{Collector, CollectorError, utils};
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cm_dashboard_shared::{Metric, SharedError};
|
use cm_dashboard_shared::Metric;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
pub mod cached_collector;
|
pub mod cached_collector;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cm_dashboard_shared::{MetricMessage, MessageEnvelope};
|
use cm_dashboard_shared::{MetricMessage, MessageEnvelope};
|
||||||
use tracing::{info, error, debug};
|
use tracing::{info, debug};
|
||||||
use zmq::{Context, Socket, SocketType};
|
use zmq::{Context, Socket, SocketType};
|
||||||
|
|
||||||
use crate::config::ZmqConfig;
|
use crate::config::ZmqConfig;
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use std::time::Instant;
|
|||||||
use tracing::{info, error, debug};
|
use tracing::{info, error, debug};
|
||||||
|
|
||||||
use crate::config::{CollectorConfig, AgentConfig};
|
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;
|
use crate::cache::MetricCacheManager;
|
||||||
|
|
||||||
/// Manages all metric collectors with intelligent caching
|
/// Manages all metric collectors with intelligent caching
|
||||||
@ -195,7 +195,7 @@ impl MetricCollectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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())
|
.map(|t| now.duration_since(*t).as_secs())
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
// Collector skipped (debug logging disabled for performance)
|
// Collector skipped (debug logging disabled for performance)
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use cm_dashboard_shared::Status;
|
use cm_dashboard_shared::Status;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use tracing::{info, debug, warn};
|
use tracing::{info, debug};
|
||||||
|
|
||||||
use crate::config::NotificationConfig;
|
use crate::config::NotificationConfig;
|
||||||
|
|
||||||
|
|||||||
@ -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"
|
|
||||||
@ -57,20 +57,8 @@ impl Dashboard {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connect to predefined hosts
|
// Connect to predefined hosts from configuration
|
||||||
let hosts = if config.hosts.predefined_hosts.is_empty() {
|
let hosts = config.hosts.predefined_hosts.clone();
|
||||||
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()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Try to connect to hosts but don't fail if none are available
|
// Try to connect to hosts but don't fail if none are available
|
||||||
match zmq_consumer.connect_to_predefined_hosts(&hosts).await {
|
match zmq_consumer.connect_to_predefined_hosts(&hosts).await {
|
||||||
@ -139,11 +127,6 @@ impl Dashboard {
|
|||||||
self.zmq_command_sender.send_command(hostname, command).await
|
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<()> {
|
pub async fn run(&mut self) -> Result<()> {
|
||||||
info!("Starting dashboard main loop");
|
info!("Starting dashboard main loop");
|
||||||
|
|||||||
@ -2,7 +2,6 @@ use anyhow::Result;
|
|||||||
use cm_dashboard_shared::{MetricMessage, MessageEnvelope, MessageType};
|
use cm_dashboard_shared::{MetricMessage, MessageEnvelope, MessageType};
|
||||||
use tracing::{info, error, debug, warn};
|
use tracing::{info, error, debug, warn};
|
||||||
use zmq::{Context, Socket, SocketType};
|
use zmq::{Context, Socket, SocketType};
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use crate::config::ZmqConfig;
|
use crate::config::ZmqConfig;
|
||||||
|
|
||||||
@ -80,11 +79,6 @@ impl ZmqConsumer {
|
|||||||
Ok(())
|
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)
|
/// Receive metrics from any connected agent (non-blocking)
|
||||||
pub async fn receive_metrics(&mut self) -> Result<Option<MetricMessage>> {
|
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
|
/// ZMQ command sender for sending commands to agents
|
||||||
pub struct ZmqCommandSender {
|
pub struct ZmqCommandSender {
|
||||||
context: Context,
|
context: Context,
|
||||||
config: ZmqConfig,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ZmqCommandSender {
|
impl ZmqCommandSender {
|
||||||
pub fn new(config: &ZmqConfig) -> Result<Self> {
|
pub fn new(_config: &ZmqConfig) -> Result<Self> {
|
||||||
let context = Context::new();
|
let context = Context::new();
|
||||||
|
|
||||||
info!("ZMQ command sender initialized");
|
info!("ZMQ command sender initialized");
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
context,
|
context,
|
||||||
config: config.clone(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,24 +164,4 @@ impl ZmqCommandSender {
|
|||||||
// Socket will be automatically closed when dropped
|
// Socket will be automatically closed when dropped
|
||||||
Ok(())
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -111,6 +111,7 @@ impl Default for HostsConfig {
|
|||||||
"simonbox".to_string(),
|
"simonbox".to_string(),
|
||||||
"steambox".to_string(),
|
"steambox".to_string(),
|
||||||
"srv01".to_string(),
|
"srv01".to_string(),
|
||||||
|
"srv02".to_string(),
|
||||||
],
|
],
|
||||||
default_host: Some("cmbox".to_string()),
|
default_host: Some("cmbox".to_string()),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
use cm_dashboard_shared::{Metric, Status};
|
use cm_dashboard_shared::{Metric, Status};
|
||||||
use std::collections::HashMap;
|
use std::time::Instant;
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
use tracing::{debug, info};
|
|
||||||
|
|
||||||
pub mod store;
|
pub mod store;
|
||||||
pub mod subscription;
|
pub mod subscription;
|
||||||
|
|
||||||
pub use store::MetricStore;
|
pub use store::MetricStore;
|
||||||
pub use subscription::SubscriptionManager;
|
|
||||||
|
|
||||||
/// Widget types that can subscribe to metrics
|
/// Widget types that can subscribe to metrics
|
||||||
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
|
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
|
||||||
@ -21,13 +18,6 @@ pub enum WidgetType {
|
|||||||
Alerts,
|
Alerts,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Metric subscription entry
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct MetricSubscription {
|
|
||||||
pub widget_type: WidgetType,
|
|
||||||
pub metric_names: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Historical metric data point
|
/// Historical metric data point
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MetricDataPoint {
|
pub struct MetricDataPoint {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
use super::{WidgetType, MetricSubscription, subscriptions};
|
use super::{WidgetType, subscriptions};
|
||||||
|
|
||||||
/// Manages metric subscriptions for widgets
|
/// Manages metric subscriptions for widgets
|
||||||
pub struct SubscriptionManager {
|
pub struct SubscriptionManager {
|
||||||
@ -41,23 +41,6 @@ impl SubscriptionManager {
|
|||||||
subscriptions::MEMORY_WIDGET_METRICS.iter().map(|&s| s.to_string()).collect()
|
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",
|
info!("Initialized default widget subscriptions for {} widgets",
|
||||||
self.widget_subscriptions.len());
|
self.widget_subscriptions.len());
|
||||||
|
|||||||
@ -330,9 +330,9 @@ impl TuiApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate how many lines we need
|
// Calculate how many lines we need
|
||||||
let mut total_lines_needed = 0;
|
let mut _total_lines_needed = 0;
|
||||||
for partitions in physical_devices.values() {
|
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;
|
let available_lines = area.height as usize;
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use ratatui::{
|
|||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use super::Widget;
|
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
|
/// Backup widget displaying backup status, services, and repository information
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use ratatui::{
|
|||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use super::Widget;
|
use super::Widget;
|
||||||
use crate::ui::theme::{Theme, Typography, Components, StatusIcons};
|
use crate::ui::theme::{Typography, StatusIcons};
|
||||||
|
|
||||||
/// CPU widget displaying load, temperature, and frequency
|
/// CPU widget displaying load, temperature, and frequency
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use ratatui::{
|
|||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use super::Widget;
|
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
|
/// Memory widget displaying usage, totals, and swap information
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::Utc;
|
||||||
|
|
||||||
/// Individual metric with value, status, and metadata
|
/// Individual metric with value, status, and metadata
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user