integrated Component temperature + Disks from sysinfo

This commit is contained in:
2025-07-31 21:26:15 +02:00
parent 0de7eb98bf
commit e1eb1fc8b7
2 changed files with 14 additions and 65 deletions

View File

@@ -18,7 +18,7 @@ chrono = "0.4"
nvml-wrapper = "0.10" nvml-wrapper = "0.10"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = ["winuser", "pdh"] } winapi = { version = "0.3", features = ["winuser", "pdh", "ifmib", "iphlpapi", "winerror"] }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
glob = "0.3" glob = "0.3"

View File

@@ -3,7 +3,7 @@ use nvml_wrapper::Nvml;
use reqwest::{Client, StatusCode}; 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::{Components, Disks, System};
use tokio::time::{interval, sleep, Instant}; use tokio::time::{interval, sleep, Instant};
// Data structures matching the C# DTOs // Data structures matching the C# DTOs
@@ -342,60 +342,7 @@ impl MetricsCollector {
let ram_size = total_memory; let ram_size = total_memory;
// Disk - updated for sysinfo 0.35 // Disk - updated for sysinfo 0.35
let (disk_size, disk_usage, disk_temp) = { let (disk_size, disk_usage, disk_temp) = get_disk_info();
let mut total_size = 0u64;
let mut total_used = 0u64;
let mut count = 0;
for disk in self.sys.disks() {
total_size += disk.total_space();
total_used += disk.total_space() - disk.available_space();
count += 1;
}
// Disk temperature (Linux only)
#[cfg(target_os = "linux")]
{
if let Ok(dir) = fs::read_dir("/sys/block") {
for entry in dir.flatten() {
if let Some(disk_name) = entry.file_name().to_str() {
if disk_name.starts_with("sd") || disk_name.starts_with("nvme") {
let temp_path = format!(
"/sys/block/{}/device/hwmon/hwmon*/temp1_input",
disk_name
);
if let Ok(paths) = glob::glob(&temp_path) {
for path in paths.flatten() {
if let Ok(content) = fs::read_to_string(path) {
if let Ok(t) = content.trim().parse::<f32>() {
temp += t / 1000.0; // Convert millidegrees
break;
}
}
}
}
}
}
}
}
}
let size_b = if count > 0 { total_size as f64 } else { 0.0 };
let usage = if total_size > 0 {
(total_used as f64 / total_size as f64) * 100.0
} else {
0.0
};
let avg_temp = if count > 0 {
disk_temp / count as f32
} else {
0.0
};
(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 {
if let Ok(device) = nvml.device_by_index(0) { if let Ok(device) = nvml.device_by_index(0) {
@@ -467,15 +414,16 @@ impl MetricsCollector {
} }
fn get_cpu_temp() -> Option<f32> { fn get_cpu_temp() -> Option<f32> {
let sys = System::new_all(); let components = Components::new_with_refreshed_list();
for component in &components {
// Try to get CPU temperature from sysinfo first if let Some(temperature) = component.temperature() {
if let Some(temp) = sys.cpus().first().and_then(|cpu| cpu.get_temperature()) { println!("{temperature}°C");
return Some(temp as f32); }
} }
None Some(0.0) // Placeholder, actual implementation depends on platform
} }
/* /*
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
@@ -576,14 +524,15 @@ None*/
fn get_disk_info() -> (f64, f64, f64) { fn get_disk_info() -> (f64, f64, f64) {
let mut sys = System::new(); let mut sys = System::new();
sys.refresh_disks(); sys.refresh_all();
sys.refresh_disks_list(); //sys.refresh_disks_list();
let mut total_size = 0u64; let mut total_size = 0u64;
let mut total_used = 0u64; let mut total_used = 0u64;
let mut count = 0; let mut count = 0;
for disk in sys.disks() { let disks = Disks::new_with_refreshed_list();
for disk in disks.list() {
// Ignoriere CD-ROMs und kleine Systempartitionen // Ignoriere CD-ROMs und kleine Systempartitionen
if disk.total_space() > 100 * 1024 * 1024 { if disk.total_space() > 100 * 1024 * 1024 {
// > 100MB // > 100MB