diff --git a/WatcherAgent/src/api.rs b/WatcherAgent/src/api.rs index ab22c26..9041032 100644 --- a/WatcherAgent/src/api.rs +++ b/WatcherAgent/src/api.rs @@ -62,7 +62,7 @@ pub async fn register_with_server( cpu_type: hardware.cpu.name.clone().unwrap_or_default(), cpu_cores: (hardware.cpu.cores).unwrap_or_default(), gpu_type: hardware.gpu.name.clone().unwrap_or_default(), - ram_size: hardware.memory.total.unwrap_or_default(), + ram_size: hardware.memory.total_size.unwrap_or_default(), }; // Try to register (will retry on failure) diff --git a/WatcherAgent/src/docker/serverclientcomm.rs b/WatcherAgent/src/docker/serverclientcomm.rs index 07d84c5..284453c 100644 --- a/WatcherAgent/src/docker/serverclientcomm.rs +++ b/WatcherAgent/src/docker/serverclientcomm.rs @@ -8,7 +8,7 @@ use crate::docker::container::{get_available_container}; use std::error::Error; use bollard::Docker; -use bollard::query_parameters::{CreateImageOptions, RestartContainerOptions, InspectContainerOptions}; +use bollard::query_parameters::{CreateImageOptions, RestartContainerOptions}; use futures_util::StreamExt; /// Handles a message from the backend server and dispatches the appropriate action. diff --git a/WatcherAgent/src/hardware/gpu.rs b/WatcherAgent/src/hardware/gpu.rs index f1064d3..ce3cf06 100644 --- a/WatcherAgent/src/hardware/gpu.rs +++ b/WatcherAgent/src/hardware/gpu.rs @@ -14,8 +14,8 @@ use std::error::Error; /// ## Units /// - `current_load`: GPU usage as a percentage (**0.0–100.0**) /// - `current_temp`: GPU temperature in **degrees Celsius (°C)** -/// - `vram_total`: Total VRAM in **megabytes (MB)** -/// - `vram_used`: Used VRAM in **megabytes (MB)** +/// - `vram_total`: Total VRAM in **bytes** +/// - `vram_used`: Used VRAM in **bytes** /// /// GPU statistics for the host system. /// @@ -23,8 +23,8 @@ use std::error::Error; /// - `name`: GPU model name (string) /// - `current_load`: GPU usage as a percentage (**0.0–100.0**) /// - `current_temp`: GPU temperature in **degrees Celsius (°C)** -/// - `vram_total`: Total VRAM in **megabytes (MB)** -/// - `vram_used`: Used VRAM in **megabytes (MB)** +/// - `vram_total`: Total VRAM in **bytes** +/// - `vram_used`: Used VRAM in **bytes** #[derive(Debug)] pub struct GpuInfo { pub name: Option, @@ -69,7 +69,7 @@ pub async fn get_gpu_info() -> Result> { /// Queries NVML for GPU metrics: temperature, load, VRAM used/total. /// /// # Returns -/// * `Result<(f64, f64, f64, f64), Box>` - Tuple of (temperature °C, load %, VRAM used MB, VRAM total MB). +/// * `Result<(f64, f64, f64, f64), Box>` - Tuple of (temperature °C, load %, VRAM used bytes, VRAM total bytes). pub fn get_gpu_metrics() -> Result<(f64, f64, f64, f64), Box> { let nvml = Nvml::init(); if let Ok(nvml) = nvml { diff --git a/WatcherAgent/src/hardware/memory.rs b/WatcherAgent/src/hardware/memory.rs index 1820299..8cc032f 100644 --- a/WatcherAgent/src/hardware/memory.rs +++ b/WatcherAgent/src/hardware/memory.rs @@ -13,33 +13,35 @@ use sysinfo::System; /// - **Error Handling:** Graceful fallback if metrics are unavailable. /// /// ## Units -/// - `total`, `used`, `free`: RAM in **megabytes (MB)** +/// - `total`, `used`, `free`: RAM in **bytes** /// /// Memory statistics for the host system. /// /// # Fields -/// - `total`: Total RAM in **megabytes (MB)** -/// - `used`: Used RAM in **megabytes (MB)** -/// - `free`: Free RAM in **megabytes (MB)** +/// - `total`: Total RAM in **bytes** +/// - `used`: Used RAM in **bytes** +/// - `free`: Free RAM in **bytes** #[derive(Debug)] pub struct MemoryInfo { - pub total: Option, + pub total_size: Option, pub used: Option, pub free: Option, + pub current_load: Option, } /// Collects memory information (total, used, free RAM). /// /// # Returns /// * `Result` - Memory statistics or error if unavailable. -pub async fn get_memory_info() -> Result { +pub async fn get_memory_info() -> Result> { let mut sys = System::new(); sys.refresh_memory(); Ok(MemoryInfo { - total: Some(sys.total_memory() as f64), + total_size: Some(sys.total_memory() as f64), used: Some(sys.used_memory() as f64), free: Some(sys.free_memory() as f64), + current_load: Some(get_memory_usage(&mut sys).unwrap() as f64) }) } @@ -50,7 +52,7 @@ pub async fn get_memory_info() -> Result { /// /// # Returns /// * `Result>` - Memory usage as percentage. -pub fn _get_memory_usage(sys: &mut System) -> Result> { +pub fn get_memory_usage(sys: &mut System) -> Result> { sys.refresh_memory(); Ok((sys.used_memory() as f64 / sys.total_memory() as f64) * 100.0) } diff --git a/WatcherAgent/src/metrics.rs b/WatcherAgent/src/metrics.rs index 9714068..16bf778 100644 --- a/WatcherAgent/src/metrics.rs +++ b/WatcherAgent/src/metrics.rs @@ -105,9 +105,9 @@ impl Collector { gpu_load: hardware.gpu.current_load.unwrap_or_default(), gpu_temp: hardware.gpu.current_temp.unwrap_or_default(), gpu_vram_size: hardware.gpu.vram_total.unwrap_or_default(), - gpu_vram_usage: hardware.gpu.vram_used.unwrap_or_default(), - ram_load: hardware.memory.used.unwrap_or_default(), - ram_size: hardware.memory.total.unwrap_or_default(), + gpu_vram_load: hardware.gpu.current_load.unwrap_or_default(), + ram_load: hardware.memory.current_load.unwrap_or_default(), + ram_size: hardware.memory.total_size.unwrap_or_default(), disk_size: hardware.disk.total_size.unwrap_or_default(), disk_usage: hardware.disk.total_used.unwrap_or_default(), disk_temp: 0.0, // not supported diff --git a/WatcherAgent/src/models.rs b/WatcherAgent/src/models.rs index 2a0a4c7..82a79ae 100644 --- a/WatcherAgent/src/models.rs +++ b/WatcherAgent/src/models.rs @@ -47,12 +47,12 @@ pub struct RegistrationDto { /// - `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)** +/// - `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)** @@ -72,8 +72,8 @@ pub struct MetricDto { pub gpu_temp: f64, #[serde(rename = "gpu_Vram_Size")] pub gpu_vram_size: f64, - #[serde(rename = "gpu_Vram_Usage")] - pub gpu_vram_usage: f64, + #[serde(rename = "gpu_Vram_Load")] + pub gpu_vram_load: f64, #[serde(rename = "ram_Load")] pub ram_load: f64, #[serde(rename = "ram_Size")]