added Option to data structs

This commit is contained in:
2025-10-06 12:43:15 +02:00
parent a7cae5e93f
commit 06cec6ff9f
6 changed files with 87 additions and 65 deletions

View File

@@ -70,11 +70,11 @@ pub async fn get_single_container_cpu_stats(
};
return Ok(Some(ContainerCpuInfo {
container_id: container_id.to_string(),
cpu_usage_percent: cpu_percent,
system_cpu_usage: cpu_stats.system_cpu_usage.unwrap_or(0),
container_cpu_usage: cpu_usage.total_usage.unwrap_or(0),
online_cpus,
container_id: Some(container_id.to_string()),
cpu_usage_percent: Some(cpu_percent),
system_cpu_usage: Some(cpu_stats.system_cpu_usage.unwrap_or(0)),
container_cpu_usage: Some(cpu_usage.total_usage.unwrap_or(0)),
online_cpus: Some(online_cpus),
}));
}
}
@@ -91,6 +91,9 @@ pub async fn get_average_cpu_usage(docker: &Docker) -> Result<f64, Box<dyn Error
return Ok(0.0);
}
let total_cpu: f64 = cpu_infos.iter().map(|cpu| cpu.cpu_usage_percent).sum();
let total_cpu: f64 = cpu_infos
.iter()
.map(|cpu| cpu.cpu_usage_percent.unwrap())
.sum();
Ok(total_cpu / cpu_infos.len() as f64)
}
}