added documentation to /docker/stats mod.rs

This commit is contained in:
2025-10-30 09:57:24 +01:00
parent 6405ab16e4
commit 4e28d57460
2 changed files with 64 additions and 20 deletions

View File

@@ -46,6 +46,20 @@ use bollard::Docker;
use std::error::Error;
/// Get container statistics for all containers using an existing Docker client
///
/// Collects comprehensive statistics for all containers including CPU usage, network I/O,
/// memory consumption, and container status. This is the primary function for gathering
/// complete container metrics in a single operation.
///
/// # Arguments
///
/// * `docker` - Reference to connected Docker client
///
/// # Returns
///
/// * `Ok((Vec<ContainerCpuInfo>, Vec<ContainerNetworkInfo>, Vec<ContainerMemoryInfo>, Vec<ContainerStatusInfo>))` -
/// Tuple containing vectors of CPU, network, memory, and status information for all containers
/// * `Err(Box<dyn Error + Send + Sync>)` - If any statistics collection fails
pub async fn get_container_stats(
docker: &Docker,
) -> Result<
@@ -66,6 +80,20 @@ pub async fn get_container_stats(
}
/// Get container statistics for a specific container
///
/// Retrieves detailed metrics for a single container identified by its ID.
/// Useful for targeted monitoring or when responding to container-specific commands.
///
/// # Arguments
///
/// * `docker` - Reference to connected Docker client
/// * `container_id` - The ID of the container to inspect
///
/// # Returns
///
/// * `Ok((Option<ContainerCpuInfo>, Option<ContainerNetworkInfo>, Option<ContainerMemoryInfo>, Option<ContainerStatusInfo>))` -
/// Tuple containing optional CPU, network, memory, and status information for the specified container
/// * `Err(Box<dyn Error + Send + Sync>)` - If statistics collection fails
pub async fn get_single_container_stats(
docker: &Docker,
container_id: &str,
@@ -84,6 +112,18 @@ pub async fn get_single_container_stats(
}
/// Get total network statistics across all containers
///
/// Calculates the sum of network receive and transmit bytes across all containers.
/// This provides an overview of total network traffic generated by all containers.
///
/// # Arguments
///
/// * `docker` - Reference to connected Docker client
///
/// # Returns
///
/// * `Ok((u64, u64))` - Tuple containing total received bytes and total transmitted bytes
/// * `Err(Box<dyn Error + Send + Sync>)` - If network statistics collection fails
pub async fn get_total_network_stats(
docker: &Docker,
) -> Result<(u64, u64), Box<dyn Error + Send + Sync>> {
@@ -91,11 +131,35 @@ pub async fn get_total_network_stats(
}
/// Get average CPU usage across all containers
///
/// Calculates the average CPU usage percentage across all running containers.
/// This provides a high-level overview of container CPU utilization.
///
/// # Arguments
///
/// * `docker` - Reference to connected Docker client
///
/// # Returns
///
/// * `Ok(f64)` - Average CPU usage percentage across all containers (0.0-100.0)
/// * `Err(Box<dyn Error + Send + Sync>)` - If CPU statistics collection fails
pub async fn get_average_cpu_usage(docker: &Docker) -> Result<f64, Box<dyn Error + Send + Sync>> {
cpu::get_average_cpu_usage(docker).await
}
/// Get total memory usage across all containers
///
/// Calculates the sum of memory usage across all containers.
/// This provides an overview of total memory consumption by all containers.
///
/// # Arguments
///
/// * `docker` - Reference to connected Docker client
///
/// # Returns
///
/// * `Ok(u64)` - Total memory usage in bytes across all containers
/// * `Err(Box<dyn Error + Send + Sync>)` - If memory statistics collection fails
pub async fn get_total_memory_usage(docker: &Docker) -> Result<u64, Box<dyn Error + Send + Sync>> {
ram::get_total_memory_usage(docker).await
}

View File

@@ -1,20 +0,0 @@
networks:
watcher-network:
driver: bridge
services:
watcher:
image: git.triggermeelmo.com/watcher/watcher-server:v0.1.11
container_name: watcher
deploy:
resources:
limits:
memory: 200M
restart: unless-stopped
env_file: .env
ports:
- "5000:5000"
volumes:
- ./watcher-volumes/data:/app/persistence
- ./watcher-volumes/dumps:/app/wwwroot/downloads/sqlite
- ./watcher-volumes/logs:/app/logs