/// # 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. /// /// ## Responsibilities /// - **DTOs:** Define payloads for registration, metrics, heartbeat, and server commands. /// - **Units:** All struct fields are documented with their units for clarity and API compatibility. /// - **Docker Info:** Structures for representing Docker container state and statistics. /// /// ## Usage /// These types are serialized/deserialized for HTTP communication and used throughout the agent for data exchange. use crate::docker::stats; use serde::{Deserialize, Serialize}; /// Registration data sent to the backend server. /// /// ## Units /// - `id`: Unique server identifier (integer) /// - `ip_address`: IPv4 or IPv6 address (string) /// - `cpu_type`: CPU model name (string) /// - `cpu_cores`: Number of physical CPU cores (integer) /// - `gpu_type`: GPU model name (string) /// - `ram_size`: Total RAM size in **megabytes (MB)** #[derive(Serialize, Debug)] pub struct RegistrationDto { #[serde(rename = "id")] pub server_id: i32, #[serde(rename = "ipAddress")] pub ip_address: String, #[serde(rename = "cpuType")] pub cpu_type: String, #[serde(rename = "cpuCores")] pub cpu_cores: i32, #[serde(rename = "gpuType")] pub gpu_type: String, #[serde(rename = "ramSize")] pub ram_size: f64, } /// Hardware and network metrics data sent to the backend server. /// /// ## Units /// - `server_id`: Unique server identifier (integer) /// - `ip_address`: IPv4 or IPv6 address (string) /// - `cpu_load`: CPU usage as a percentage (**0.0–100.0**) /// - `cpu_temp`: CPU temperature in **degrees Celsius (°C)** /// - `gpu_load`: GPU usage as a percentage (**0.0–100.0**) /// - `gpu_temp`: GPU temperature in **degrees Celsius (°C)** /// - `gpu_vram_size`: Total GPU VRAM in **bytes** /// - `gpu_vram_load`: GPU Usage of VRAM as a percentage (**0.0–100.0**) /// - `ram_load`: RAM usage as a percentage (**0.0–100.0**) /// - `ram_size`: Total RAM in **bytes** /// - `disk_size`: Total disk size in **bytes** /// - `disk_usage`: Used disk space in **bytes** /// - `disk_temp`: Disk temperature in **degrees Celsius (°C)** (if available) /// - `net_rx`: Network receive rate in **bytes per second (B/s)** /// - `net_tx`: Network transmit rate in **bytes per second (B/s)** #[derive(Serialize, Debug)] pub struct MetricDto { #[serde(rename = "serverId")] pub server_id: i32, #[serde(rename = "ipAddress")] pub ip_address: String, #[serde(rename = "cpu_Load")] pub cpu_load: f64, #[serde(rename = "cpu_Temp")] pub cpu_temp: f64, #[serde(rename = "gpu_Load")] pub gpu_load: f64, #[serde(rename = "gpu_Temp")] pub gpu_temp: f64, #[serde(rename = "gpu_Vram_Size")] pub gpu_vram_size: f64, #[serde(rename = "gpu_Vram_Load")] pub gpu_vram_load: f64, #[serde(rename = "ram_Load")] pub ram_load: f64, #[serde(rename = "ram_Size")] pub ram_size: f64, #[serde(rename = "disk_Size")] pub disk_size: f64, #[serde(rename = "disk_Usage")] pub disk_usage: f64, #[serde(rename = "disk_Temp")] pub disk_temp: f64, #[serde(rename = "net_In")] pub net_rx: f64, #[serde(rename = "net_Out")] pub net_tx: f64, } /// Detailed disk information for each detected disk. /// /// ## Units /// - `disk_total_space`: Total disk space in **bytes** /// - `disk_available_space`: Available disk space in **bytes** /// - `disk_used_space`: Used disk space in **bytes** /// - `component_disk_temperature`: Disk temperature in **degrees Celsius (°C)** #[derive(Serialize, Debug)] pub struct DiskInfoDetailed { pub disk_name: String, pub disk_kind: String, pub disk_total_space: f64, pub disk_available_space: f64, pub disk_used_space: f64, pub disk_mount_point: String, pub component_disk_label: String, pub component_disk_temperature: f32, } /// Response containing server ID and IP address. /// /// ## Units /// - `id`: Unique server identifier (integer) /// - `ip_address`: IPv4 or IPv6 address (string) #[derive(Deserialize)] pub struct IdResponse { pub id: i32, #[serde(rename = "ipAddress")] pub ip_address: String, } /// Heartbeat message data sent to the backend server. /// /// ## Units /// - `ip_address`: IPv4 or IPv6 address (string) #[derive(Serialize)] pub struct HeartbeatDto { #[serde(rename = "IpAddress")] pub ip_address: String, } /// Hardware summary data for diagnostics and registration. /// /// ## Units /// - `cpu_type`: CPU model name (string) /// - `cpu_cores`: Number of physical CPU cores (integer) /// - `gpu_type`: GPU model name (string) /// - `ram_size`: Total RAM size in **megabytes (MB)** /// - `ip_address`: IPv4 or IPv6 address (string) #[derive(Serialize, Debug)] pub struct HardwareDto { pub cpu_type: String, pub cpu_cores: i32, pub gpu_type: String, pub ram_size: f64, pub ip_address: String, } /// Command message received from the backend server. /// /// ## Fields /// - `message_type`: Type of command (e.g., "update_image", "restart_container", "stop_agent") /// - `data`: Command payload (arbitrary JSON) /// - `message_id`: Unique identifier for acknowledgment #[derive(Debug, Deserialize, Clone)] pub struct ServerMessage { // Define your message structure here pub message_type: String, pub data: serde_json::Value, pub message_id: String, // Add an ID for acknowledgment } /// Acknowledgment payload sent to the backend server for command messages. /// /// ## Fields /// - `message_id`: Unique identifier of the acknowledged message /// - `status`: Status string ("success", "error", etc.) /// - `details`: Additional details or error messages #[derive(Debug, Serialize, Clone)] pub struct Acknowledgment { pub message_id: String, pub status: String, // "success" or "error" pub details: String, } /// Docker container information for agent and managed containers. /// /// ## Fields /// - `ID`: Container ID (first 12 hex digits, integer) /// - `image`: Docker image name (string) /// - `Name`: Container name (string) /// - `Status`: Container status ("running", "stopped", etc.) /// - `_net_in`: Network receive rate in **bytes per second (B/s)** /// - `_net_out`: Network transmit rate in **bytes per second (B/s)** /// - `_cpu_load`: CPU usage as a percentage (**0.0–100.0**) #[derive(Debug, Serialize, Clone)] pub struct DockerContainerRegistrationDto { pub server_id: u32, pub containers: Vec, } #[derive(Debug, Serialize, Clone)] pub struct DockerContainerDto { pub id: String, pub image: String, pub name: String, } #[derive(Debug, Serialize, Clone)] pub struct DockerContainerMetricDto { pub id: String, pub status: String, // "running";"stopped";others pub network: stats::ContainerNetworkInfo, pub cpu: stats::ContainerCpuInfo, }