fixed comments

This commit is contained in:
2025-10-01 12:11:34 +02:00
parent 8c49a63a50
commit f78e48900a
11 changed files with 146 additions and 144 deletions

View File

@@ -1,17 +1,17 @@
//! # API Module /// # API Module
//! ///
//! This module provides all HTTP communication between WatcherAgent and the backend server. /// This module provides all HTTP communication between WatcherAgent and the backend server.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **Registration:** Registers the agent with the backend and retrieves its server ID and IP address. /// - **Registration:** Registers the agent with the backend and retrieves its server ID and IP address.
//! - **Heartbeat:** Periodically sends heartbeat signals to indicate liveness. /// - **Heartbeat:** Periodically sends heartbeat signals to indicate liveness.
//! - **Metrics Reporting:** Sends collected hardware and network metrics to the backend. /// - **Metrics Reporting:** Sends collected hardware and network metrics to the backend.
//! - **Command Listening:** Polls for and executes remote commands from the backend (e.g., update image, restart container). /// - **Command Listening:** Polls for and executes remote commands from the backend (e.g., update image, restart container).
//! ///
//! ## Usage /// ## Usage
//! These functions are called from the main agent loop and background tasks. All network operations are asynchronous and robust to transient failures. /// These functions are called from the main agent loop and background tasks. All network operations are asynchronous and robust to transient failures.
use std::time::Duration; use std::time::Duration;
use crate::hardware::HardwareInfo; use crate::hardware::HardwareInfo;

View File

@@ -1,13 +1,13 @@
//! # Docker Module /// # Docker Module
//! ///
//! This module provides Docker integration for WatcherAgent, including container enumeration, statistics, and lifecycle management. /// This module provides Docker integration for WatcherAgent, including container enumeration, statistics, and lifecycle management.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **Container Management:** Lists, inspects, and manages Docker containers relevant to the agent. /// - **Container Management:** Lists, inspects, and manages Docker containers relevant to the agent.
//! - **Statistics Aggregation:** Collects network and CPU statistics for all managed containers. /// - **Statistics Aggregation:** Collects network and CPU statistics for all managed containers.
//! - **Lifecycle Operations:** Supports container restart and ID lookup for agent self-management. /// - **Lifecycle Operations:** Supports container restart and ID lookup for agent self-management.
//! ///
pub mod container; pub mod container;
pub mod serverclientcomm; pub mod serverclientcomm;

View File

@@ -2,20 +2,20 @@ use anyhow::Result;
use std::error::Error; use std::error::Error;
use sysinfo::System; use sysinfo::System;
//! # CPU Hardware Module /// # CPU Hardware Module
//! ///
//! This module provides CPU information collection for WatcherAgent, including load, temperature, and system uptime. /// This module provides CPU information collection for WatcherAgent, including load, temperature, and system uptime.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **CPU Detection:** Identifies CPU model and core count. /// - **CPU Detection:** Identifies CPU model and core count.
//! - **Metric Collection:** Queries CPU load, temperature, and uptime. /// - **Metric Collection:** Queries CPU load, temperature, and uptime.
//! - **Error Handling:** Graceful fallback if metrics are unavailable. /// - **Error Handling:** Graceful fallback if metrics are unavailable.
//! ///
//! ## Units /// ## Units
//! - `current_load`: CPU usage as a percentage (**0.0100.0**) /// - `current_load`: CPU usage as a percentage (**0.0100.0**)
//! - `current_temp`: CPU temperature in **degrees Celsius (°C)** /// - `current_temp`: CPU temperature in **degrees Celsius (°C)**
//! - `uptime`: System uptime in **seconds (s)** /// - `uptime`: System uptime in **seconds (s)**
//! ///
/// CPU statistics for the host system. /// CPU statistics for the host system.
/// ///
/// # Fields /// # Fields

View File

@@ -7,19 +7,19 @@ use sysinfo::{Component, Components, Disk, Disks};
use serde::Serialize; use serde::Serialize;
//! # Disk Hardware Module /// # Disk Hardware Module
//! ///
//! This module provides disk information collection for WatcherAgent, including total and per-disk statistics and temperature data. /// This module provides disk information collection for WatcherAgent, including total and per-disk statistics and temperature data.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **Disk Enumeration:** Lists all physical disks and their properties. /// - **Disk Enumeration:** Lists all physical disks and their properties.
//! - **Usage Calculation:** Computes total and per-disk usage, available space, and usage percentage. /// - **Usage Calculation:** Computes total and per-disk usage, available space, and usage percentage.
//! - **Temperature Monitoring:** Associates disk components with temperature sensors if available. /// - **Temperature Monitoring:** Associates disk components with temperature sensors if available.
//! ///
//! ## Units /// ## Units
//! - All sizes are in **bytes** unless otherwise noted. /// - All sizes are in **bytes** unless otherwise noted.
//! - Temperatures are in **degrees Celsius (°C)**. /// - Temperatures are in **degrees Celsius (°C)**.
//! ///
/// Summary of disk statistics for the system. /// Summary of disk statistics for the system.
/// ///
/// # Fields /// # Fields

View File

@@ -2,21 +2,21 @@ use anyhow::Result;
use nvml_wrapper::Nvml; use nvml_wrapper::Nvml;
use std::error::Error; use std::error::Error;
//! # GPU Hardware Module /// # GPU Hardware Module
//! ///
//! This module provides GPU information collection for WatcherAgent, including load, temperature, and VRAM statistics. /// This module provides GPU information collection for WatcherAgent, including load, temperature, and VRAM statistics.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **GPU Detection:** Identifies GPU model and capabilities. /// - **GPU Detection:** Identifies GPU model and capabilities.
//! - **Metric Collection:** Queries GPU load, temperature, and VRAM usage using NVML (NVIDIA only). /// - **Metric Collection:** Queries GPU load, temperature, and VRAM usage using NVML (NVIDIA only).
//! - **Error Handling:** Graceful fallback if GPU or NVML is unavailable. /// - **Error Handling:** Graceful fallback if GPU or NVML is unavailable.
//! ///
//! ## Units /// ## Units
//! - `current_load`: GPU usage as a percentage (**0.0100.0**) /// - `current_load`: GPU usage as a percentage (**0.0100.0**)
//! - `current_temp`: GPU temperature in **degrees Celsius (°C)** /// - `current_temp`: GPU temperature in **degrees Celsius (°C)**
//! - `vram_total`: Total VRAM in **megabytes (MB)** /// - `vram_total`: Total VRAM in **megabytes (MB)**
//! - `vram_used`: Used VRAM in **megabytes (MB)** /// - `vram_used`: Used VRAM in **megabytes (MB)**
//! ///
/// GPU statistics for the host system. /// GPU statistics for the host system.
/// ///
/// # Fields /// # Fields

View File

@@ -3,18 +3,18 @@ use std::error::Error;
use anyhow::Result; use anyhow::Result;
use sysinfo::System; use sysinfo::System;
//! # Memory Hardware Module /// # Memory Hardware Module
//! ///
//! This module provides memory information collection for WatcherAgent, including total, used, and free RAM. /// This module provides memory information collection for WatcherAgent, including total, used, and free RAM.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **Memory Detection:** Queries system for total, used, and free RAM. /// - **Memory Detection:** Queries system for total, used, and free RAM.
//! - **Usage Calculation:** Computes memory usage percentage. /// - **Usage Calculation:** Computes memory usage percentage.
//! - **Error Handling:** Graceful fallback if metrics are unavailable. /// - **Error Handling:** Graceful fallback if metrics are unavailable.
//! ///
//! ## Units /// ## Units
//! - `total`, `used`, `free`: RAM in **megabytes (MB)** /// - `total`, `used`, `free`: RAM in **megabytes (MB)**
//! ///
/// Memory statistics for the host system. /// Memory statistics for the host system.
/// ///
/// # Fields /// # Fields

View File

@@ -14,14 +14,14 @@ pub use memory::get_memory_info;
pub use network::get_network_info; pub use network::get_network_info;
pub use network::NetworkMonitor; pub use network::NetworkMonitor;
//! # Hardware Module /// # Hardware Module
//! ///
//! This module aggregates all hardware subsystems for WatcherAgent, providing unified collection and access to CPU, GPU, memory, disk, and network statistics. /// This module aggregates all hardware subsystems for WatcherAgent, providing unified collection and access to CPU, GPU, memory, disk, and network statistics.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **Subsystem Aggregation:** Combines all hardware modules into a single struct for easy access. /// - **Subsystem Aggregation:** Combines all hardware modules into a single struct for easy access.
//! - **Unified Collection:** Provides a single async method to collect all hardware metrics at once. /// - **Unified Collection:** Provides a single async method to collect all hardware metrics at once.
//! ///
/// Aggregated hardware statistics for the host system. /// Aggregated hardware statistics for the host system.
/// ///
/// # Fields /// # Fields

View File

@@ -2,18 +2,18 @@ use std::error::Error;
use std::result::Result; use std::result::Result;
use std::time::Instant; use std::time::Instant;
//! # Network Hardware Module /// # Network Hardware Module
//! ///
//! This module provides network information collection for WatcherAgent, including interface enumeration and bandwidth statistics. /// This module provides network information collection for WatcherAgent, including interface enumeration and bandwidth statistics.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **Interface Detection:** Lists all network interfaces. /// - **Interface Detection:** Lists all network interfaces.
//! - **Bandwidth Monitoring:** Tracks receive/transmit rates using a rolling monitor. /// - **Bandwidth Monitoring:** Tracks receive/transmit rates using a rolling monitor.
//! - **Error Handling:** Graceful fallback if metrics are unavailable. /// - **Error Handling:** Graceful fallback if metrics are unavailable.
//! ///
//! ## Units /// ## Units
//! - `rx_rate`, `tx_rate`: Network bandwidth in **bytes per second (B/s)** /// - `rx_rate`, `tx_rate`: Network bandwidth in **bytes per second (B/s)**
//! ///
/// Network statistics for the host system. /// Network statistics for the host system.
/// ///
/// # Fields /// # Fields

View File

@@ -1,31 +1,31 @@
//! # WatcherAgent /// # WatcherAgent
//! ///
//! **WatcherAgent** is a cross-platform system monitoring agent written in Rust. /// **WatcherAgent** is a cross-platform system monitoring agent written in Rust.
//! ///
//! ## Overview /// ## Overview
//! This agent collects real-time hardware metrics (CPU, GPU, RAM, disk, network) and communicates with a backend server for registration, reporting, and remote control. It is designed for deployment in environments where automated monitoring and remote management of system resources is required. /// This agent collects real-time hardware metrics (CPU, GPU, RAM, disk, network) and communicates with a backend server for registration, reporting, and remote control. It is designed for deployment in environments where automated monitoring and remote management of system resources is required.
//! ///
//! ## Features /// ## Features
//! - **Hardware Metrics:** Collects CPU, GPU, RAM, disk, and network statistics using platform-specific APIs. /// - **Hardware Metrics:** Collects CPU, GPU, RAM, disk, and network statistics using platform-specific APIs.
//! - **Docker Integration:** Detects and manages its own Docker container, supports image updates and container restarts. /// - **Docker Integration:** Detects and manages its own Docker container, supports image updates and container restarts.
//! - **Server Communication:** Registers with a backend server, sends periodic heartbeats, and reports metrics securely. /// - **Server Communication:** Registers with a backend server, sends periodic heartbeats, and reports metrics securely.
//! - **Remote Commands:** Listens for and executes commands from the backend (e.g., update image, restart container, stop agent). /// - **Remote Commands:** Listens for and executes commands from the backend (e.g., update image, restart container, stop agent).
//! ///
//! ## Modules /// ## Modules
//! - [`api`]: Handles HTTP communication with the backend server (registration, heartbeat, metrics, commands). /// - [`api`]: Handles HTTP communication with the backend server (registration, heartbeat, metrics, commands).
//! - [`hardware`]: Collects hardware metrics from the host system (CPU, GPU, RAM, disk, network). /// - [`hardware`]: Collects hardware metrics from the host system (CPU, GPU, RAM, disk, network).
//! - [`metrics`]: Orchestrates metric collection and reporting. /// - [`metrics`]: Orchestrates metric collection and reporting.
//! - [`models`]: Defines data structures for server communication and metrics. /// - [`models`]: Defines data structures for server communication and metrics.
//! - [`docker`]: Integrates with Docker for container management and agent lifecycle. /// - [`docker`]: Integrates with Docker for container management and agent lifecycle.
//! ///
//! ## Usage /// ## Usage
//! Run the agent with the backend server URL as an argument: /// Run the agent with the backend server URL as an argument:
//! ```sh /// ```sh
//! watcheragent <server-url> /// watcheragent <server-url>
//! ``` /// ```
//! ///
//! The agent will register itself, start collecting metrics, and listen for remote commands. /// The agent will register itself, start collecting metrics, and listen for remote commands.
pub mod api; pub mod api;
pub mod hardware; pub mod hardware;
@@ -34,6 +34,8 @@ pub mod models;
pub mod docker; pub mod docker;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use bollard::Docker; use bollard::Docker;
use std::env;
use std::error::Error;

View File

@@ -1,16 +1,16 @@
//! # Metrics Module /// # Metrics Module
//! ///
//! This module orchestrates the collection and reporting of hardware and network metrics for WatcherAgent. /// This module orchestrates the collection and reporting of hardware and network metrics for WatcherAgent.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **Metric Collection:** Gathers real-time statistics from all hardware subsystems (CPU, GPU, RAM, disk, network). /// - **Metric Collection:** Gathers real-time statistics from all hardware subsystems (CPU, GPU, RAM, disk, network).
//! - **Reporting:** Periodically sends metrics to the backend server using the API module. /// - **Reporting:** Periodically sends metrics to the backend server using the API module.
//! - **Error Handling:** Robust to hardware failures and network errors, with retry logic and logging. /// - **Error Handling:** Robust to hardware failures and network errors, with retry logic and logging.
//! ///
//! ## Usage /// ## Usage
//! The [`Collector`] struct is instantiated in the main loop and runs as a background task, continuously collecting and reporting metrics. /// The [`Collector`] struct is instantiated in the main loop and runs as a background task, continuously collecting and reporting metrics.
use std::error::Error; use std::error::Error;
use std::time::Duration; use std::time::Duration;

View File

@@ -1,16 +1,16 @@
//! # Models Module /// # Models Module
//! ///
//! This module defines all data structures (DTOs) used for communication between WatcherAgent and the backend server, as well as hardware metrics and Docker container info. /// This module defines all data structures (DTOs) used for communication between WatcherAgent and the backend server, as well as hardware metrics and Docker container info.
//! ///
//! ## Responsibilities /// ## Responsibilities
//! - **DTOs:** Define payloads for registration, metrics, heartbeat, and server commands. /// - **DTOs:** Define payloads for registration, metrics, heartbeat, and server commands.
//! - **Units:** All struct fields are documented with their units for clarity and API compatibility. /// - **Units:** All struct fields are documented with their units for clarity and API compatibility.
//! - **Docker Info:** Structures for representing Docker container state and statistics. /// - **Docker Info:** Structures for representing Docker container state and statistics.
//! ///
//! ## Usage /// ## Usage
//! These types are serialized/deserialized for HTTP communication and used throughout the agent for data exchange. /// These types are serialized/deserialized for HTTP communication and used throughout the agent for data exchange.
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Registration data sent to the backend server. /// Registration data sent to the backend server.