Remove debug prints and unused code
All checks were successful
Build and Release / build-and-release (push) Successful in 1m19s
All checks were successful
Build and Release / build-and-release (push) Successful in 1m19s
- Remove all debug println statements - Remove unused service_tracker module - Remove unused struct fields and methods - Remove empty placeholder files (cpu.rs, memory.rs, defaults.rs) - Fix all compiler warnings - Clean build with zero warnings Version bump to 0.1.159
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use async_trait::async_trait;
|
||||
use chrono::{NaiveDateTime, DateTime};
|
||||
use cm_dashboard_shared::{AgentData, BackupData, BackupDiskData};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -19,10 +19,8 @@ pub struct DiskCollector {
|
||||
/// A physical drive with its filesystems
|
||||
#[derive(Debug, Clone)]
|
||||
struct PhysicalDrive {
|
||||
name: String, // e.g., "nvme0n1", "sda"
|
||||
name: String, // e.g., "nvme0n1", "sda"
|
||||
health: String, // SMART health status
|
||||
temperature_celsius: Option<f32>, // Drive temperature
|
||||
wear_percent: Option<f32>, // SSD wear level
|
||||
filesystems: Vec<Filesystem>, // mounted filesystems on this drive
|
||||
}
|
||||
|
||||
@@ -351,8 +349,6 @@ impl DiskCollector {
|
||||
let physical_drive = PhysicalDrive {
|
||||
name: drive_name,
|
||||
health: "UNKNOWN".to_string(), // Will be updated with SMART data
|
||||
temperature_celsius: None,
|
||||
wear_percent: None,
|
||||
filesystems,
|
||||
};
|
||||
physical_drives.push(physical_drive);
|
||||
|
||||
@@ -5,21 +5,18 @@ use std::process::Command;
|
||||
use tracing::debug;
|
||||
|
||||
use super::{Collector, CollectorError};
|
||||
use crate::config::NixOSConfig;
|
||||
|
||||
/// NixOS system information collector with structured data output
|
||||
///
|
||||
///
|
||||
/// This collector gathers NixOS-specific information like:
|
||||
/// - System generation/build information
|
||||
/// - Version information
|
||||
/// - Agent version from Nix store path
|
||||
pub struct NixOSCollector {
|
||||
config: NixOSConfig,
|
||||
}
|
||||
pub struct NixOSCollector;
|
||||
|
||||
impl NixOSCollector {
|
||||
pub fn new(config: NixOSConfig) -> Self {
|
||||
Self { config }
|
||||
pub fn new(_config: crate::config::NixOSConfig) -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
/// Collect NixOS system information and populate AgentData
|
||||
|
||||
@@ -22,8 +22,6 @@ pub struct SystemdCollector {
|
||||
struct ServiceCacheState {
|
||||
/// Last collection time for performance tracking
|
||||
last_collection: Option<Instant>,
|
||||
/// Cached service data
|
||||
services: Vec<ServiceInfo>,
|
||||
/// Cached complete service data with sub-services
|
||||
cached_service_data: Vec<ServiceData>,
|
||||
/// Interesting services to monitor (cached after discovery)
|
||||
@@ -50,20 +48,10 @@ struct ServiceStatusInfo {
|
||||
sub_state: String,
|
||||
}
|
||||
|
||||
/// Internal service information
|
||||
#[derive(Debug, Clone)]
|
||||
struct ServiceInfo {
|
||||
name: String,
|
||||
status: String, // "active", "inactive", "failed", etc.
|
||||
memory_mb: f32, // Memory usage in MB
|
||||
disk_gb: f32, // Disk usage in GB
|
||||
}
|
||||
|
||||
impl SystemdCollector {
|
||||
pub fn new(config: SystemdConfig) -> Self {
|
||||
let state = ServiceCacheState {
|
||||
last_collection: None,
|
||||
services: Vec::new(),
|
||||
cached_service_data: Vec::new(),
|
||||
monitored_services: Vec::new(),
|
||||
service_status_cache: std::collections::HashMap::new(),
|
||||
@@ -73,7 +61,7 @@ impl SystemdCollector {
|
||||
last_nginx_check_time: None,
|
||||
nginx_check_interval_seconds: config.nginx_check_interval_seconds,
|
||||
};
|
||||
|
||||
|
||||
Self {
|
||||
state: RwLock::new(state),
|
||||
config,
|
||||
@@ -95,7 +83,6 @@ impl SystemdCollector {
|
||||
};
|
||||
|
||||
// Collect service data for each monitored service
|
||||
let mut services = Vec::new();
|
||||
let mut complete_service_data = Vec::new();
|
||||
for service_name in &monitored_services {
|
||||
match self.get_service_status(service_name) {
|
||||
@@ -145,14 +132,6 @@ impl SystemdCollector {
|
||||
}
|
||||
}
|
||||
|
||||
let service_info = ServiceInfo {
|
||||
name: service_name.clone(),
|
||||
status: active_status.clone(),
|
||||
memory_mb,
|
||||
disk_gb,
|
||||
};
|
||||
services.push(service_info);
|
||||
|
||||
// Create complete service data
|
||||
let service_data = ServiceData {
|
||||
name: service_name.clone(),
|
||||
@@ -177,7 +156,6 @@ impl SystemdCollector {
|
||||
{
|
||||
let mut state = self.state.write().unwrap();
|
||||
state.last_collection = Some(start_time);
|
||||
state.services = services;
|
||||
state.cached_service_data = complete_service_data;
|
||||
}
|
||||
|
||||
@@ -483,25 +461,6 @@ impl SystemdCollector {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get service memory usage (if available)
|
||||
fn get_service_memory(&self, service: &str) -> Option<f32> {
|
||||
let output = Command::new("systemctl")
|
||||
.args(&["show", &format!("{}.service", service), "--property=MemoryCurrent"])
|
||||
.output()
|
||||
.ok()?;
|
||||
|
||||
let output_str = String::from_utf8(output.stdout).ok()?;
|
||||
for line in output_str.lines() {
|
||||
if line.starts_with("MemoryCurrent=") {
|
||||
let memory_str = line.strip_prefix("MemoryCurrent=")?;
|
||||
if let Ok(memory_bytes) = memory_str.parse::<u64>() {
|
||||
return Some(memory_bytes as f32 / (1024.0 * 1024.0)); // Convert to MB
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Calculate service status, taking user-stopped services into account
|
||||
fn calculate_service_status(&self, service_name: &str, active_status: &str) -> Status {
|
||||
match active_status.to_lowercase().as_str() {
|
||||
@@ -549,7 +508,7 @@ impl SystemdCollector {
|
||||
/// Check if service collection cache should be updated
|
||||
fn should_update_cache(&self) -> bool {
|
||||
let state = self.state.read().unwrap();
|
||||
|
||||
|
||||
match state.last_collection {
|
||||
None => true,
|
||||
Some(last) => {
|
||||
@@ -559,16 +518,6 @@ impl SystemdCollector {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get cached service data if available and fresh
|
||||
fn get_cached_services(&self) -> Option<Vec<ServiceInfo>> {
|
||||
if !self.should_update_cache() {
|
||||
let state = self.state.read().unwrap();
|
||||
Some(state.services.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Get cached complete service data with sub-services if available and fresh
|
||||
fn get_cached_complete_services(&self) -> Option<Vec<ServiceData>> {
|
||||
if !self.should_update_cache() {
|
||||
|
||||
Reference in New Issue
Block a user