Remove all unused code and fix build warnings
- Remove unused struct fields: tier, config_name, last_collection_time - Remove unused structs: PerformanceMetrics, PerfMonitor - Remove unused methods: get_performance_metrics, get_collector_names, get_stats - Remove unused utility functions and system helpers - Remove unused config fields from CPU and Memory collectors - Keep config fields that are actually used (DiskCollector, etc.) - Remove unused proxy_pass_url variable and assignments - Fix duplicate hostname variable declaration - Achieve zero build warnings without functionality changes
This commit is contained in:
parent
049ac53629
commit
eb268922bd
3
agent/src/cache/cached_metric.rs
vendored
3
agent/src/cache/cached_metric.rs
vendored
@ -1,4 +1,4 @@
|
|||||||
use cm_dashboard_shared::{CacheTier, Metric};
|
use cm_dashboard_shared::Metric;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
/// A cached metric with metadata
|
/// A cached metric with metadata
|
||||||
@ -7,5 +7,4 @@ pub struct CachedMetric {
|
|||||||
pub metric: Metric,
|
pub metric: Metric,
|
||||||
pub collected_at: Instant,
|
pub collected_at: Instant,
|
||||||
pub access_count: u64,
|
pub access_count: u64,
|
||||||
pub tier: Option<CacheTier>,
|
|
||||||
}
|
}
|
||||||
|
|||||||
1
agent/src/cache/mod.rs
vendored
1
agent/src/cache/mod.rs
vendored
@ -41,7 +41,6 @@ impl ConfigurableCache {
|
|||||||
metric: metric.clone(),
|
metric: metric.clone(),
|
||||||
collected_at: Instant::now(),
|
collected_at: Instant::now(),
|
||||||
access_count: 1,
|
access_count: 1,
|
||||||
tier: self.config.get_tier_for_metric(&metric.name).cloned(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cache.insert(metric.name.clone(), cached_metric);
|
cache.insert(metric.name.clone(), cached_metric);
|
||||||
|
|||||||
@ -15,7 +15,6 @@ use crate::config::CpuConfig;
|
|||||||
/// - No process spawning
|
/// - No process spawning
|
||||||
/// - <0.1ms collection time target
|
/// - <0.1ms collection time target
|
||||||
pub struct CpuCollector {
|
pub struct CpuCollector {
|
||||||
config: CpuConfig,
|
|
||||||
name: String,
|
name: String,
|
||||||
load_thresholds: HysteresisThresholds,
|
load_thresholds: HysteresisThresholds,
|
||||||
temperature_thresholds: HysteresisThresholds,
|
temperature_thresholds: HysteresisThresholds,
|
||||||
@ -35,7 +34,6 @@ impl CpuCollector {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
config,
|
|
||||||
name: "cpu".to_string(),
|
name: "cpu".to_string(),
|
||||||
load_thresholds,
|
load_thresholds,
|
||||||
temperature_thresholds,
|
temperature_thresholds,
|
||||||
@ -243,7 +241,4 @@ impl Collector for CpuCollector {
|
|||||||
Ok(metrics)
|
Ok(metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_performance_metrics(&self) -> Option<super::PerformanceMetrics> {
|
|
||||||
None // Performance tracking handled by cache system
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use std::process::Command;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use super::{Collector, CollectorError, PerformanceMetrics};
|
use super::{Collector, CollectorError};
|
||||||
|
|
||||||
/// Information about a mounted disk
|
/// Information about a mounted disk
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -22,7 +22,6 @@ struct MountedDisk {
|
|||||||
used: String, // e.g., "45G"
|
used: String, // e.g., "45G"
|
||||||
available: String, // e.g., "75G"
|
available: String, // e.g., "75G"
|
||||||
usage_percent: f32, // e.g., 38.5
|
usage_percent: f32, // e.g., 38.5
|
||||||
config_name: Option<String>, // Name from config if UUID-based
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disk usage collector for monitoring filesystem sizes
|
/// Disk usage collector for monitoring filesystem sizes
|
||||||
@ -117,7 +116,6 @@ impl DiskCollector {
|
|||||||
used,
|
used,
|
||||||
available,
|
available,
|
||||||
usage_percent: usage_percent as f32,
|
usage_percent: usage_percent as f32,
|
||||||
config_name: Some(fs_config.name.clone()),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
@ -611,7 +609,4 @@ impl Collector for DiskCollector {
|
|||||||
Ok(metrics)
|
Ok(metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_performance_metrics(&self) -> Option<PerformanceMetrics> {
|
|
||||||
None // Performance tracking handled by cache system
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,6 @@ use crate::config::MemoryConfig;
|
|||||||
/// - No regex or complex parsing
|
/// - No regex or complex parsing
|
||||||
/// - <0.1ms collection time target
|
/// - <0.1ms collection time target
|
||||||
pub struct MemoryCollector {
|
pub struct MemoryCollector {
|
||||||
config: MemoryConfig,
|
|
||||||
name: String,
|
name: String,
|
||||||
usage_thresholds: HysteresisThresholds,
|
usage_thresholds: HysteresisThresholds,
|
||||||
}
|
}
|
||||||
@ -43,7 +42,6 @@ impl MemoryCollector {
|
|||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
config,
|
|
||||||
name: "memory".to_string(),
|
name: "memory".to_string(),
|
||||||
usage_thresholds,
|
usage_thresholds,
|
||||||
}
|
}
|
||||||
@ -231,7 +229,4 @@ impl Collector for MemoryCollector {
|
|||||||
Ok(metrics)
|
Ok(metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_performance_metrics(&self) -> Option<super::PerformanceMetrics> {
|
|
||||||
None // Performance tracking handled by cache system
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,6 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cm_dashboard_shared::{Metric, StatusTracker};
|
use cm_dashboard_shared::{Metric, StatusTracker};
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
/// Performance metrics for a collector
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct PerformanceMetrics {
|
|
||||||
pub last_collection_time: Duration,
|
|
||||||
pub collection_efficiency_percent: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod backup;
|
pub mod backup;
|
||||||
pub mod cpu;
|
pub mod cpu;
|
||||||
@ -28,10 +21,6 @@ pub trait Collector: Send + Sync {
|
|||||||
/// Collect all metrics this collector provides
|
/// Collect all metrics this collector provides
|
||||||
async fn collect(&self, status_tracker: &mut StatusTracker) -> Result<Vec<Metric>, CollectorError>;
|
async fn collect(&self, status_tracker: &mut StatusTracker) -> Result<Vec<Metric>, CollectorError>;
|
||||||
|
|
||||||
/// Get performance metrics for monitoring collector efficiency
|
|
||||||
fn get_performance_metrics(&self) -> Option<PerformanceMetrics> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,12 +6,10 @@ use std::sync::RwLock;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use super::{Collector, CollectorError, PerformanceMetrics};
|
use super::{Collector, CollectorError};
|
||||||
|
|
||||||
/// Systemd collector for monitoring systemd services
|
/// Systemd collector for monitoring systemd services
|
||||||
pub struct SystemdCollector {
|
pub struct SystemdCollector {
|
||||||
/// Performance tracking
|
|
||||||
last_collection_time: Option<std::time::Duration>,
|
|
||||||
/// Cached state with thread-safe interior mutability
|
/// Cached state with thread-safe interior mutability
|
||||||
state: RwLock<ServiceCacheState>,
|
state: RwLock<ServiceCacheState>,
|
||||||
}
|
}
|
||||||
@ -36,7 +34,6 @@ struct ServiceCacheState {
|
|||||||
impl SystemdCollector {
|
impl SystemdCollector {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
last_collection_time: None,
|
|
||||||
state: RwLock::new(ServiceCacheState {
|
state: RwLock::new(ServiceCacheState {
|
||||||
monitored_services: Vec::new(),
|
monitored_services: Vec::new(),
|
||||||
last_discovery_time: None,
|
last_discovery_time: None,
|
||||||
@ -481,9 +478,6 @@ impl Collector for SystemdCollector {
|
|||||||
Ok(metrics)
|
Ok(metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_performance_metrics(&self) -> Option<PerformanceMetrics> {
|
|
||||||
None // Performance tracking handled by cache system
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemdCollector {
|
impl SystemdCollector {
|
||||||
@ -755,7 +749,6 @@ impl SystemdCollector {
|
|||||||
fn parse_server_block(&self, lines: &[&str], start_index: &mut usize) -> Option<String> {
|
fn parse_server_block(&self, lines: &[&str], start_index: &mut usize) -> Option<String> {
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
let mut server_names = Vec::new();
|
let mut server_names = Vec::new();
|
||||||
let mut proxy_pass_url = None;
|
|
||||||
let mut has_redirect = false;
|
let mut has_redirect = false;
|
||||||
let mut i = *start_index + 1;
|
let mut i = *start_index + 1;
|
||||||
let mut brace_count = 1;
|
let mut brace_count = 1;
|
||||||
@ -785,16 +778,6 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract proxy_pass URL (backend IP:port)
|
|
||||||
if trimmed.starts_with("proxy_pass") {
|
|
||||||
if let Some(url_part) = trimmed.strip_prefix("proxy_pass") {
|
|
||||||
let url_clean = url_part.trim().trim_end_matches(';');
|
|
||||||
if !url_clean.is_empty() {
|
|
||||||
proxy_pass_url = Some(url_clean.to_string());
|
|
||||||
debug!("Found proxy_pass in block: {}", url_clean);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for redirects (skip redirect-only servers)
|
// Check for redirects (skip redirect-only servers)
|
||||||
if trimmed.contains("return") && (trimmed.contains("301") || trimmed.contains("302")) {
|
if trimmed.contains("return") && (trimmed.contains("301") || trimmed.contains("302")) {
|
||||||
|
|||||||
@ -9,7 +9,6 @@ use crate::config::ZmqConfig;
|
|||||||
pub struct ZmqHandler {
|
pub struct ZmqHandler {
|
||||||
publisher: Socket,
|
publisher: Socket,
|
||||||
command_receiver: Socket,
|
command_receiver: Socket,
|
||||||
config: ZmqConfig,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ZmqHandler {
|
impl ZmqHandler {
|
||||||
@ -41,7 +40,6 @@ impl ZmqHandler {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
publisher,
|
publisher,
|
||||||
command_receiver,
|
command_receiver,
|
||||||
config: config.clone(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -237,21 +237,6 @@ impl MetricCollectionManager {
|
|||||||
Ok(all_metrics)
|
Ok(all_metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get names of all registered collectors
|
|
||||||
pub fn get_collector_names(&self) -> Vec<String> {
|
|
||||||
self.collectors
|
|
||||||
.iter()
|
|
||||||
.map(|c| c.name().to_string())
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get collector statistics
|
|
||||||
pub fn get_stats(&self) -> HashMap<String, bool> {
|
|
||||||
self.collectors
|
|
||||||
.iter()
|
|
||||||
.map(|c| (c.name().to_string(), true)) // All collectors are enabled
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get all cached metrics from the cache manager
|
/// Get all cached metrics from the cache manager
|
||||||
pub async fn get_all_cached_metrics(&self) -> Result<Vec<Metric>> {
|
pub async fn get_all_cached_metrics(&self) -> Result<Vec<Metric>> {
|
||||||
@ -263,20 +248,4 @@ impl MetricCollectionManager {
|
|||||||
Ok(cached_metrics)
|
Ok(cached_metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine which collector handles a specific metric
|
|
||||||
fn get_collector_for_metric(&self, metric_name: &str) -> String {
|
|
||||||
if metric_name.starts_with("cpu_") {
|
|
||||||
"cpu".to_string()
|
|
||||||
} else if metric_name.starts_with("memory_") {
|
|
||||||
"memory".to_string()
|
|
||||||
} else if metric_name.starts_with("disk_") {
|
|
||||||
"disk".to_string()
|
|
||||||
} else if metric_name.starts_with("service_") {
|
|
||||||
"systemd".to_string()
|
|
||||||
} else if metric_name.starts_with("backup_") {
|
|
||||||
"backup".to_string()
|
|
||||||
} else {
|
|
||||||
"unknown".to_string()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -295,8 +295,4 @@ impl NotificationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get current metric statuses
|
|
||||||
pub fn get_metric_statuses(&self) -> &HashMap<String, Status> {
|
|
||||||
&self.metric_statuses
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,91 +1 @@
|
|||||||
// Utility functions for the agent
|
// Utility functions for the agent (empty module)
|
||||||
|
|
||||||
/// System information utilities
|
|
||||||
pub mod system {
|
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
/// Get number of CPU cores efficiently
|
|
||||||
pub fn get_cpu_count() -> Result<usize, std::io::Error> {
|
|
||||||
// Try /proc/cpuinfo first (most reliable)
|
|
||||||
if let Ok(content) = fs::read_to_string("/proc/cpuinfo") {
|
|
||||||
let count = content
|
|
||||||
.lines()
|
|
||||||
.filter(|line| line.starts_with("processor"))
|
|
||||||
.count();
|
|
||||||
|
|
||||||
if count > 0 {
|
|
||||||
return Ok(count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to nproc equivalent
|
|
||||||
match std::thread::available_parallelism() {
|
|
||||||
Ok(count) => Ok(count.get()),
|
|
||||||
Err(_) => Ok(1), // Default to 1 core if all else fails
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if running in container
|
|
||||||
pub fn is_container() -> bool {
|
|
||||||
// Check for common container indicators
|
|
||||||
fs::metadata("/.dockerenv").is_ok()
|
|
||||||
|| fs::read_to_string("/proc/1/cgroup")
|
|
||||||
.map(|content| content.contains("docker") || content.contains("containerd"))
|
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Time utilities
|
|
||||||
pub mod time {
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
/// Measure execution time of a closure
|
|
||||||
pub fn measure_time<F, R>(f: F) -> (R, Duration)
|
|
||||||
where
|
|
||||||
F: FnOnce() -> R,
|
|
||||||
{
|
|
||||||
let start = Instant::now();
|
|
||||||
let result = f();
|
|
||||||
let duration = start.elapsed();
|
|
||||||
(result, duration)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Performance monitoring utilities
|
|
||||||
pub mod perf {
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
use tracing::warn;
|
|
||||||
|
|
||||||
/// Performance monitor for critical operations
|
|
||||||
pub struct PerfMonitor {
|
|
||||||
operation: String,
|
|
||||||
start: Instant,
|
|
||||||
warning_threshold: Duration,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PerfMonitor {
|
|
||||||
pub fn new(operation: &str, warning_threshold: Duration) -> Self {
|
|
||||||
Self {
|
|
||||||
operation: operation.to_string(),
|
|
||||||
start: Instant::now(),
|
|
||||||
warning_threshold,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_ms(operation: &str, warning_threshold_ms: u64) -> Self {
|
|
||||||
Self::new(operation, Duration::from_millis(warning_threshold_ms))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for PerfMonitor {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
let elapsed = self.start.elapsed();
|
|
||||||
if elapsed > self.warning_threshold {
|
|
||||||
warn!(
|
|
||||||
"Performance warning: {} took {:?} (threshold: {:?})",
|
|
||||||
self.operation, elapsed, self.warning_threshold
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -140,9 +140,6 @@ impl TuiApp {
|
|||||||
|
|
||||||
// Get the current hostname (localhost) for auto-selection
|
// Get the current hostname (localhost) for auto-selection
|
||||||
let localhost = gethostname::gethostname().to_string_lossy().to_string();
|
let localhost = gethostname::gethostname().to_string_lossy().to_string();
|
||||||
|
|
||||||
// Prioritize localhost if it becomes available, but respect user navigation
|
|
||||||
let localhost = gethostname::gethostname().to_string_lossy().to_string();
|
|
||||||
if !self.available_hosts.is_empty() {
|
if !self.available_hosts.is_empty() {
|
||||||
if self.available_hosts.contains(&localhost) && !self.user_navigated_away {
|
if self.available_hosts.contains(&localhost) && !self.user_navigated_away {
|
||||||
// Localhost is available and user hasn't navigated away - switch to it
|
// Localhost is available and user hasn't navigated away - switch to it
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user