added commentation
This commit is contained in:
@@ -1,6 +1,27 @@
|
||||
|
||||
|
||||
//! # 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 serde::{Deserialize, Serialize};
|
||||
|
||||
// Data structures matching the C# DTOs
|
||||
/// 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")]
|
||||
@@ -17,6 +38,24 @@ pub struct RegistrationDto {
|
||||
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 **megabytes (MB)**
|
||||
/// - `gpu_vram_usage`: Used GPU VRAM in **megabytes (MB)**
|
||||
/// - `ram_load`: Used RAM in **megabytes (MB)**
|
||||
/// - `ram_size`: Total RAM in **megabytes (MB)**
|
||||
/// - `disk_size`: Total disk size in **megabytes (MB)**
|
||||
/// - `disk_usage`: Used disk space in **megabytes (MB)**
|
||||
/// - `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")]
|
||||
@@ -51,6 +90,13 @@ pub struct MetricDto {
|
||||
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,
|
||||
@@ -63,6 +109,11 @@ pub struct DiskInfoDetailed {
|
||||
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,
|
||||
@@ -70,12 +121,24 @@ pub struct IdResponse {
|
||||
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,
|
||||
@@ -85,6 +148,12 @@ pub struct HardwareDto {
|
||||
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
|
||||
@@ -93,6 +162,12 @@ pub struct ServerMessage {
|
||||
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,
|
||||
@@ -100,6 +175,16 @@ pub struct Acknowledgment {
|
||||
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 DockerContainer {
|
||||
pub ID: u32,
|
||||
|
Reference in New Issue
Block a user