Testing
This commit is contained in:
@@ -389,6 +389,38 @@ impl ServiceCollector {
|
||||
Ok((parse(parts[0])?, parse(parts[1])?, parse(parts[2])?))
|
||||
}
|
||||
|
||||
fn determine_cpu_status(&self, cpu_load_5: f32) -> String {
|
||||
if cpu_load_5 >= 8.0 {
|
||||
"critical".to_string()
|
||||
} else if cpu_load_5 >= 5.0 {
|
||||
"warning".to_string()
|
||||
} else {
|
||||
"ok".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn determine_memory_status(&self, usage_percent: f32) -> String {
|
||||
if usage_percent >= 95.0 {
|
||||
"critical".to_string()
|
||||
} else if usage_percent >= 80.0 {
|
||||
"warning".to_string()
|
||||
} else {
|
||||
"ok".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn determine_services_status(&self, healthy: usize, degraded: usize, failed: usize) -> String {
|
||||
if failed > 0 {
|
||||
"critical".to_string()
|
||||
} else if degraded > 0 {
|
||||
"warning".to_string()
|
||||
} else if healthy > 0 {
|
||||
"ok".to_string()
|
||||
} else {
|
||||
"unknown".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_cpu_cstate_info(&self) -> Option<Vec<String>> {
|
||||
// Read C-state information to show all sleep state distributions
|
||||
let mut cstate_times: Vec<(String, u64)> = Vec::new();
|
||||
@@ -966,6 +998,19 @@ impl Collector for ServiceCollector {
|
||||
|
||||
let (cpu_load_1, cpu_load_5, cpu_load_15) =
|
||||
self.get_cpu_load().await.unwrap_or((0.0, 0.0, 0.0));
|
||||
let cpu_status = self.determine_cpu_status(cpu_load_5);
|
||||
|
||||
// Calculate memory usage percentage and status
|
||||
let memory_usage_percent = if system_memory.total_mb > 0.0 {
|
||||
(system_memory.used_mb / system_memory.total_mb) * 100.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let memory_status = self.determine_memory_status(memory_usage_percent);
|
||||
|
||||
// Calculate overall services status
|
||||
let services_status = self.determine_services_status(healthy, degraded, failed);
|
||||
|
||||
let cpu_cstate_info = self.get_cpu_cstate_info().await;
|
||||
let cpu_temp_c = self.get_cpu_temperature_c().await;
|
||||
let (gpu_load_percent, gpu_temp_c) = self.get_gpu_metrics().await;
|
||||
@@ -980,15 +1025,18 @@ impl Collector for ServiceCollector {
|
||||
"healthy": healthy,
|
||||
"degraded": degraded,
|
||||
"failed": failed,
|
||||
"services_status": services_status,
|
||||
"memory_used_mb": total_memory_used,
|
||||
"memory_quota_mb": total_memory_quota,
|
||||
"system_memory_used_mb": system_memory.used_mb,
|
||||
"system_memory_total_mb": system_memory.total_mb,
|
||||
"memory_status": memory_status,
|
||||
"disk_used_gb": total_disk_used,
|
||||
"disk_total_gb": total_disk_used, // For services, total = used (no quota concept)
|
||||
"cpu_load_1": cpu_load_1,
|
||||
"cpu_load_5": cpu_load_5,
|
||||
"cpu_load_15": cpu_load_15,
|
||||
"cpu_status": cpu_status,
|
||||
"cpu_cstate": cpu_cstate_info,
|
||||
"cpu_temp_c": cpu_temp_c,
|
||||
"gpu_load_percent": gpu_load_percent,
|
||||
|
||||
Reference in New Issue
Block a user