added Option to data structs
This commit is contained in:
@@ -6,30 +6,30 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ContainerCpuInfo {
|
||||
pub container_id: String,
|
||||
pub cpu_usage_percent: f64,
|
||||
pub system_cpu_usage: u64,
|
||||
pub container_cpu_usage: u64,
|
||||
pub online_cpus: u32,
|
||||
pub container_id: Option<String>,
|
||||
pub cpu_usage_percent: Option<f64>,
|
||||
pub system_cpu_usage: Option<u64>,
|
||||
pub container_cpu_usage: Option<u64>,
|
||||
pub online_cpus: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ContainerNetworkInfo {
|
||||
pub container_id: String,
|
||||
pub rx_bytes: u64,
|
||||
pub tx_bytes: u64,
|
||||
pub rx_packets: u64,
|
||||
pub tx_packets: u64,
|
||||
pub rx_errors: u64,
|
||||
pub tx_errors: u64,
|
||||
pub container_id: Option<String>,
|
||||
pub rx_bytes: Option<u64>,
|
||||
pub tx_bytes: Option<u64>,
|
||||
pub rx_packets: Option<u64>,
|
||||
pub tx_packets: Option<u64>,
|
||||
pub rx_errors: Option<u64>,
|
||||
pub tx_errors: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ContainerMemoryInfo {
|
||||
pub container_id: String,
|
||||
pub memory_usage: u64,
|
||||
pub memory_limit: u64,
|
||||
pub memory_usage_percent: f64,
|
||||
pub container_id: Option<String>,
|
||||
pub memory_usage: Option<u64>,
|
||||
pub memory_limit: Option<u64>,
|
||||
pub memory_usage_percent: Option<f64>,
|
||||
}
|
||||
|
||||
use bollard::Docker;
|
||||
@@ -38,7 +38,14 @@ use std::error::Error;
|
||||
/// Get container statistics for all containers using an existing Docker client
|
||||
pub async fn get_container_stats(
|
||||
docker: &Docker,
|
||||
) -> Result<(Vec<ContainerCpuInfo>, Vec<ContainerNetworkInfo>, Vec<ContainerMemoryInfo>), Box<dyn Error + Send + Sync>> {
|
||||
) -> Result<
|
||||
(
|
||||
Vec<ContainerCpuInfo>,
|
||||
Vec<ContainerNetworkInfo>,
|
||||
Vec<ContainerMemoryInfo>,
|
||||
),
|
||||
Box<dyn Error + Send + Sync>,
|
||||
> {
|
||||
let cpu_infos = cpu::get_all_containers_cpu_stats(docker).await?;
|
||||
let net_infos = network::get_all_containers_network_stats(docker).await?;
|
||||
let mem_infos = ram::get_all_containers_memory_stats(docker).await?;
|
||||
@@ -50,8 +57,14 @@ pub async fn get_container_stats(
|
||||
pub async fn get_single_container_stats(
|
||||
docker: &Docker,
|
||||
container_id: &str,
|
||||
) -> Result<(Option<ContainerCpuInfo>, Option<ContainerNetworkInfo>, Option<ContainerMemoryInfo>), Box<dyn Error + Send + Sync>>
|
||||
{
|
||||
) -> Result<
|
||||
(
|
||||
Option<ContainerCpuInfo>,
|
||||
Option<ContainerNetworkInfo>,
|
||||
Option<ContainerMemoryInfo>,
|
||||
),
|
||||
Box<dyn Error + Send + Sync>,
|
||||
> {
|
||||
let cpu_info = cpu::get_single_container_cpu_stats(docker, container_id).await?;
|
||||
let net_info = network::get_single_container_network_stats(docker, container_id).await?;
|
||||
let mem_info = ram::get_single_container_memory_stats(docker, container_id).await?;
|
||||
@@ -74,4 +87,4 @@ pub async fn get_average_cpu_usage(docker: &Docker) -> Result<f64, Box<dyn Error
|
||||
/// Get total memory usage across all containers
|
||||
pub async fn get_total_memory_usage(docker: &Docker) -> Result<u64, Box<dyn Error + Send + Sync>> {
|
||||
ram::get_total_memory_usage(docker).await
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user