65 lines
2.3 KiB
Rust
65 lines
2.3 KiB
Rust
// Exemple avec seuils personnalisés
|
|
use system_monitor::{SystemMonitor, ResourceThreshold, get_cpu_usage, get_memory_usage, get_disk_usage};
|
|
|
|
fn main() {
|
|
println!("🎛️ Surveillance avec seuils personnalisés\n");
|
|
|
|
// Définir des seuils personnalisés
|
|
let custom_thresholds = vec![
|
|
ResourceThreshold::new(
|
|
"CPU".to_string(),
|
|
get_cpu_usage,
|
|
90.0, // Seuil CPU plus élevé
|
|
).with_critical_threshold(98.0),
|
|
ResourceThreshold::new(
|
|
"Memory".to_string(),
|
|
get_memory_usage,
|
|
75.0, // Seuil mémoire plus bas
|
|
).with_critical_threshold(90.0),
|
|
ResourceThreshold::new(
|
|
"Disk".to_string(),
|
|
get_disk_usage,
|
|
85.0, // Seuil disque personnalisé
|
|
).with_critical_threshold(95.0),
|
|
];
|
|
|
|
// Créer le moniteur avec les seuils personnalisés
|
|
let mut monitor = SystemMonitor::new_with_thresholds(custom_thresholds);
|
|
|
|
// Afficher la configuration
|
|
println!("Configuration des seuils:");
|
|
for threshold in &monitor.thresholds {
|
|
let critical_info = threshold.critical_threshold
|
|
.map(|c| format!(" (critique: {}%)", c))
|
|
.unwrap_or_default();
|
|
println!(" {} : {}%{}", threshold.name, threshold.threshold, critical_info);
|
|
}
|
|
println!();
|
|
|
|
// Vérifier les seuils
|
|
let violations = monitor.check_thresholds();
|
|
|
|
if violations.is_empty() {
|
|
println!("✅ Toutes les métriques sont dans les seuils acceptables");
|
|
} else {
|
|
println!("🚨 Violations avec seuils personnalisés:");
|
|
for violation in violations {
|
|
let severity_icon = match violation.severity {
|
|
system_monitor::Severity::Warning => "⚠️",
|
|
system_monitor::Severity::Critical => "🚨",
|
|
};
|
|
println!(" {} {} : {:.2}% (seuil: {:.2}%)",
|
|
severity_icon,
|
|
violation.metric_name,
|
|
violation.current_value,
|
|
violation.threshold);
|
|
}
|
|
}
|
|
|
|
println!("\n📊 État détaillé:");
|
|
let metrics = monitor.get_metrics();
|
|
println!(" CPU: {:.1}%", metrics.cpu_usage);
|
|
println!(" Mémoire: {:.1}%", metrics.memory_usage);
|
|
println!(" Disque: {:.1}%", metrics.disk_usage);
|
|
}
|