removed all scalings
This commit is contained in:
@@ -4,7 +4,7 @@ use reqwest::{Client, StatusCode};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{error::Error, fs, process::Command, time::Duration};
|
use std::{error::Error, fs, process::Command, time::Duration};
|
||||||
use sysinfo::{CpuExt, DiskExt, System, SystemExt};
|
use sysinfo::{CpuExt, DiskExt, System, SystemExt};
|
||||||
use tokio::time::{interval, sleep};
|
use tokio::time::{interval, sleep, Instant};
|
||||||
|
|
||||||
// Data structures matching the C# DTOs
|
// Data structures matching the C# DTOs
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
@@ -79,6 +79,22 @@ struct HardwareInfo {
|
|||||||
ip_address: String,
|
ip_address: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct NetworkState {
|
||||||
|
prev_rx: u64,
|
||||||
|
prev_tx: u64,
|
||||||
|
last_update: Instant,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NetworkState {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
prev_rx: 0,
|
||||||
|
prev_tx: 0,
|
||||||
|
last_update: Instant::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HardwareInfo {
|
impl HardwareInfo {
|
||||||
async fn collect() -> Result<Self, Box<dyn Error>> {
|
async fn collect() -> Result<Self, Box<dyn Error>> {
|
||||||
let mut sys = System::new();
|
let mut sys = System::new();
|
||||||
@@ -276,6 +292,7 @@ struct MetricsCollector {
|
|||||||
nvml: Option<Nvml>,
|
nvml: Option<Nvml>,
|
||||||
server_id: i32,
|
server_id: i32,
|
||||||
ip_address: String,
|
ip_address: String,
|
||||||
|
network_state: NetworkState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetricsCollector {
|
impl MetricsCollector {
|
||||||
@@ -285,6 +302,7 @@ impl MetricsCollector {
|
|||||||
nvml: Nvml::init().ok(),
|
nvml: Nvml::init().ok(),
|
||||||
server_id,
|
server_id,
|
||||||
ip_address,
|
ip_address,
|
||||||
|
network_state: NetworkState::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +338,7 @@ impl MetricsCollector {
|
|||||||
let total_memory = self.sys.total_memory();
|
let total_memory = self.sys.total_memory();
|
||||||
let used_memory = self.sys.used_memory();
|
let used_memory = self.sys.used_memory();
|
||||||
let ram_load = (used_memory as f64 / total_memory as f64) * 100.0;
|
let ram_load = (used_memory as f64 / total_memory as f64) * 100.0;
|
||||||
let ram_size = (total_memory as f64) / 1024.0 / 1024.0;
|
let ram_size = total_memory as f64; // in B
|
||||||
|
|
||||||
// Disk
|
// Disk
|
||||||
let disk = self.sys.disks().first();
|
let disk = self.sys.disks().first();
|
||||||
@@ -364,11 +382,7 @@ impl MetricsCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let size_gb = if count > 0 {
|
let size_b = if count > 0 { total_size as f64 } else { 0.0 };
|
||||||
(total_size as f64) / 1024.0 / 1024.0 / 1024.0
|
|
||||||
} else {
|
|
||||||
0.0
|
|
||||||
};
|
|
||||||
|
|
||||||
let usage = if total_size > 0 {
|
let usage = if total_size > 0 {
|
||||||
(total_used as f64 / total_size as f64) * 100.0
|
(total_used as f64 / total_size as f64) * 100.0
|
||||||
@@ -378,7 +392,7 @@ impl MetricsCollector {
|
|||||||
|
|
||||||
let avg_temp = if count > 0 { temp / count as f32 } else { 0.0 };
|
let avg_temp = if count > 0 { temp / count as f32 } else { 0.0 };
|
||||||
|
|
||||||
(size_gb, usage, avg_temp)
|
(size_b, usage, avg_temp as f64)
|
||||||
};
|
};
|
||||||
// GPU (NVIDIA)
|
// GPU (NVIDIA)
|
||||||
let (gpu_temp, gpu_load, vram_used, vram_total) = if let Some(nvml) = &self.nvml {
|
let (gpu_temp, gpu_load, vram_used, vram_total) = if let Some(nvml) = &self.nvml {
|
||||||
@@ -391,13 +405,8 @@ impl MetricsCollector {
|
|||||||
.map(|u| u.gpu as f64)
|
.map(|u| u.gpu as f64)
|
||||||
.unwrap_or(0.0);
|
.unwrap_or(0.0);
|
||||||
let mem = device.memory_info().ok();
|
let mem = device.memory_info().ok();
|
||||||
let used = mem
|
let used = mem.clone().map(|m| (m.used as f64)).unwrap_or(0.0); // B
|
||||||
.clone()
|
let total = mem.map(|m| (m.total as f64)).unwrap_or(0.0); // B
|
||||||
.map(|m| (m.used as f64) / 1024.0 / 1024.0 / 1024.0)
|
|
||||||
.unwrap_or(0.0); // GB
|
|
||||||
let total = mem
|
|
||||||
.map(|m| (m.total as f64) / 1024.0 / 1024.0 / 1024.0)
|
|
||||||
.unwrap_or(0.0); // GB
|
|
||||||
(temp, load, used, total)
|
(temp, load, used, total)
|
||||||
} else {
|
} else {
|
||||||
(0.0, 0.0, 0.0, 0.0)
|
(0.0, 0.0, 0.0, 0.0)
|
||||||
@@ -406,10 +415,30 @@ impl MetricsCollector {
|
|||||||
(0.0, 0.0, 0.0, 0.0)
|
(0.0, 0.0, 0.0, 0.0)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Network (convert bytes to bits)
|
// Network metrics
|
||||||
let (net_in, net_out) = get_network_traffic().unwrap_or((0, 0));
|
let (current_rx, current_tx) = get_network_traffic().unwrap_or((0, 0));
|
||||||
let net_in_bits = (net_in as f64) * 8.0;
|
let elapsed_secs = self.network_state.last_update.elapsed().as_secs_f64();
|
||||||
let net_out_bits = (net_out as f64) * 8.0;
|
self.network_state.last_update = Instant::now();
|
||||||
|
|
||||||
|
// Calculate the difference since the last call
|
||||||
|
let net_in = if self.network_state.prev_rx > 0 && current_rx >= self.network_state.prev_rx {
|
||||||
|
((current_rx - self.network_state.prev_rx) as f64 * 8.0) / elapsed_secs
|
||||||
|
// bits per second
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
let net_out = if self.network_state.prev_tx > 0 && current_tx >= self.network_state.prev_tx
|
||||||
|
{
|
||||||
|
((current_tx - self.network_state.prev_tx) as f64 * 8.0) / elapsed_secs
|
||||||
|
// bits per second
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
// Store the current values for the next call
|
||||||
|
self.network_state.prev_rx = current_rx;
|
||||||
|
self.network_state.prev_tx = current_tx;
|
||||||
|
|
||||||
MetricDto {
|
MetricDto {
|
||||||
server_id: self.server_id,
|
server_id: self.server_id,
|
||||||
@@ -428,9 +457,9 @@ impl MetricsCollector {
|
|||||||
ram_size,
|
ram_size,
|
||||||
disk_size,
|
disk_size,
|
||||||
disk_usage: disk_usage,
|
disk_usage: disk_usage,
|
||||||
disk_temp: 0.0, // not supported
|
disk_temp: disk_temp, // not supported
|
||||||
net_in: net_in_bits,
|
net_in,
|
||||||
net_out: net_out_bits,
|
net_out,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -591,7 +620,6 @@ fn get_disk_info() -> (f64, f64, f64) {
|
|||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
fn get_network_traffic() -> Option<(u64, u64)> {
|
fn get_network_traffic() -> Option<(u64, u64)> {
|
||||||
use std::mem::size_of;
|
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
use winapi::shared::ifmib::{MIB_IFROW, MIB_IFTABLE};
|
use winapi::shared::ifmib::{MIB_IFROW, MIB_IFTABLE};
|
||||||
use winapi::um::iphlpapi::GetIfTable;
|
use winapi::um::iphlpapi::GetIfTable;
|
||||||
|
Reference in New Issue
Block a user