use super::*;
pub trait PerformanceMonitor: Send + Sync + std::fmt::Debug {
fn start_monitoring(&mut self) -> Result<(), AnalysisError>;
fn stop_monitoring(&mut self) -> Result<(), AnalysisError>;
fn get_current_metrics(&self) -> Result<HashMap<String, f64>, AnalysisError>;
fn get_monitor_name(&self) -> &str;
fn is_active(&self) -> bool;
}
#[derive(Debug)]
pub struct CpuMonitor {
active: bool,
}
impl Default for CpuMonitor {
fn default() -> Self {
Self::new()
}
}
impl CpuMonitor {
pub const fn new() -> Self {
Self { active: false }
}
}
impl PerformanceMonitor for CpuMonitor {
fn start_monitoring(&mut self) -> Result<(), AnalysisError> {
self.active = true;
Ok(())
}
fn stop_monitoring(&mut self) -> Result<(), AnalysisError> {
self.active = false;
Ok(())
}
fn get_current_metrics(&self) -> Result<HashMap<String, f64>, AnalysisError> {
if !self.active {
return Err(AnalysisError::DataCollectionError(
"Monitor not active".to_string(),
));
}
let mut metrics = HashMap::new();
metrics.insert("cpu_utilization".to_string(), 45.5); Ok(metrics)
}
fn get_monitor_name(&self) -> &'static str {
"CPU Monitor"
}
fn is_active(&self) -> bool {
self.active
}
}
#[derive(Debug)]
pub struct MemoryMonitor {
active: bool,
}
impl Default for MemoryMonitor {
fn default() -> Self {
Self::new()
}
}
impl MemoryMonitor {
pub const fn new() -> Self {
Self { active: false }
}
}
impl PerformanceMonitor for MemoryMonitor {
fn start_monitoring(&mut self) -> Result<(), AnalysisError> {
self.active = true;
Ok(())
}
fn stop_monitoring(&mut self) -> Result<(), AnalysisError> {
self.active = false;
Ok(())
}
fn get_current_metrics(&self) -> Result<HashMap<String, f64>, AnalysisError> {
if !self.active {
return Err(AnalysisError::DataCollectionError(
"Monitor not active".to_string(),
));
}
let mut metrics = HashMap::new();
metrics.insert("memory_utilization".to_string(), 65.2); Ok(metrics)
}
fn get_monitor_name(&self) -> &'static str {
"Memory Monitor"
}
fn is_active(&self) -> bool {
self.active
}
}
#[derive(Debug)]
pub struct IoMonitor {
active: bool,
}
impl Default for IoMonitor {
fn default() -> Self {
Self::new()
}
}
impl IoMonitor {
pub const fn new() -> Self {
Self { active: false }
}
}
impl PerformanceMonitor for IoMonitor {
fn start_monitoring(&mut self) -> Result<(), AnalysisError> {
self.active = true;
Ok(())
}
fn stop_monitoring(&mut self) -> Result<(), AnalysisError> {
self.active = false;
Ok(())
}
fn get_current_metrics(&self) -> Result<HashMap<String, f64>, AnalysisError> {
if !self.active {
return Err(AnalysisError::DataCollectionError(
"Monitor not active".to_string(),
));
}
let mut metrics = HashMap::new();
metrics.insert("io_utilization".to_string(), 25.8); Ok(metrics)
}
fn get_monitor_name(&self) -> &'static str {
"I/O Monitor"
}
fn is_active(&self) -> bool {
self.active
}
}
#[derive(Debug)]
pub struct NetworkMonitor {
active: bool,
}
impl Default for NetworkMonitor {
fn default() -> Self {
Self::new()
}
}
impl NetworkMonitor {
pub const fn new() -> Self {
Self { active: false }
}
}
impl PerformanceMonitor for NetworkMonitor {
fn start_monitoring(&mut self) -> Result<(), AnalysisError> {
self.active = true;
Ok(())
}
fn stop_monitoring(&mut self) -> Result<(), AnalysisError> {
self.active = false;
Ok(())
}
fn get_current_metrics(&self) -> Result<HashMap<String, f64>, AnalysisError> {
if !self.active {
return Err(AnalysisError::DataCollectionError(
"Monitor not active".to_string(),
));
}
let mut metrics = HashMap::new();
metrics.insert("network_utilization".to_string(), 15.3); Ok(metrics)
}
fn get_monitor_name(&self) -> &'static str {
"Network Monitor"
}
fn is_active(&self) -> bool {
self.active
}
}