From 4e28d57460632457ad6562505842113530892505 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Thu, 30 Oct 2025 09:57:24 +0100 Subject: [PATCH] added documentation to /docker/stats mod.rs --- WatcherAgent/src/docker/stats/mod.rs | 64 ++++++++++++++++++++++++++++ docker-compose.yaml | 20 --------- 2 files changed, 64 insertions(+), 20 deletions(-) delete mode 100644 docker-compose.yaml diff --git a/WatcherAgent/src/docker/stats/mod.rs b/WatcherAgent/src/docker/stats/mod.rs index 336f4b1..86a430b 100644 --- a/WatcherAgent/src/docker/stats/mod.rs +++ b/WatcherAgent/src/docker/stats/mod.rs @@ -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, Vec, Vec, Vec))` - +/// Tuple containing vectors of CPU, network, memory, and status information for all containers +/// * `Err(Box)` - 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, Option, Option, Option))` - +/// Tuple containing optional CPU, network, memory, and status information for the specified container +/// * `Err(Box)` - 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)` - If network statistics collection fails pub async fn get_total_network_stats( docker: &Docker, ) -> Result<(u64, u64), Box> { @@ -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)` - If CPU statistics collection fails pub async fn get_average_cpu_usage(docker: &Docker) -> Result> { 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)` - If memory statistics collection fails pub async fn get_total_memory_usage(docker: &Docker) -> Result> { ram::get_total_memory_usage(docker).await } diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 3aac9f1..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -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