alles umbauen teil 1
This commit is contained in:
@@ -12,13 +12,13 @@ serde_json = "1.0"
|
|||||||
tokio = { version = "1.37", features = ["full"] }
|
tokio = { version = "1.37", features = ["full"] }
|
||||||
local-ip-address = "0.5"
|
local-ip-address = "0.5"
|
||||||
reqwest = { version = "0.11", default-features = false, features = ["json", "blocking", "cookies", "rustls-tls"] }
|
reqwest = { version = "0.11", default-features = false, features = ["json", "blocking", "cookies", "rustls-tls"] }
|
||||||
sysinfo = "0.29"
|
sysinfo = "0.35"
|
||||||
metrics = "0.24.2"
|
metrics = "0.24.2"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
nvml-wrapper = "0.10"
|
nvml-wrapper = "0.10"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["winuser", "pdh", "pdhmsg"] }
|
winapi = { version = "0.3.9", features = ["winuser", "pdh"] }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
glob = "0.3"
|
glob = "0.3"
|
@@ -97,17 +97,18 @@ impl NetworkState {
|
|||||||
|
|
||||||
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_all();
|
||||||
sys.refresh_cpu();
|
sys.refresh_cpu_all();
|
||||||
sys.refresh_memory();
|
sys.refresh_memory();
|
||||||
|
|
||||||
let cpus = sys.cpus();
|
let cpus = sys.cpus();
|
||||||
let cpu_type = cpus
|
let cpu_type = if !cpus.is_empty() {
|
||||||
.get(0)
|
cpus[0].brand().to_string()
|
||||||
.map(|c| c.brand().to_string())
|
} else {
|
||||||
.unwrap_or("Unknown CPU".to_string());
|
"Unknown CPU".to_string()
|
||||||
|
};
|
||||||
let cpu_cores = cpus.len() as i32;
|
let cpu_cores = cpus.len() as i32;
|
||||||
let ram_gb = (sys.total_memory() as f64); // in Bytes
|
let ram_bytes = sys.total_memory() as f64;
|
||||||
let gpu_type = Self::detect_gpu_name();
|
let gpu_type = Self::detect_gpu_name();
|
||||||
let ip_address = local_ip_address::local_ip()?.to_string();
|
let ip_address = local_ip_address::local_ip()?.to_string();
|
||||||
|
|
||||||
@@ -115,7 +116,7 @@ impl HardwareInfo {
|
|||||||
cpu_type,
|
cpu_type,
|
||||||
cpu_cores,
|
cpu_cores,
|
||||||
gpu_type,
|
gpu_type,
|
||||||
ram_size: ram_gb,
|
ram_size: ram_bytes,
|
||||||
ip_address,
|
ip_address,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -330,23 +331,20 @@ impl MetricsCollector {
|
|||||||
fn collect_metrics(&mut self) -> MetricDto {
|
fn collect_metrics(&mut self) -> MetricDto {
|
||||||
self.sys.refresh_all();
|
self.sys.refresh_all();
|
||||||
|
|
||||||
// CPU
|
// CPU - updated for sysinfo 0.35
|
||||||
let cpu_load = self.sys.global_cpu_info().cpu_usage() as f64;
|
let cpu_load = self.sys.global_cpu_usage() as f64;
|
||||||
let cpu_temp = get_cpu_temp().unwrap_or(0.0) as f64;
|
let cpu_temp = get_cpu_temp().unwrap_or(0.0) as f64;
|
||||||
|
|
||||||
// RAM
|
// RAM - updated for sysinfo 0.35
|
||||||
let total_memory = self.sys.total_memory();
|
let total_memory = self.sys.total_memory() as f64;
|
||||||
let used_memory = self.sys.used_memory();
|
let used_memory = self.sys.used_memory() as f64;
|
||||||
let ram_load = (used_memory as f64 / total_memory as f64) * 100.0;
|
let ram_load = (used_memory / total_memory) * 100.0;
|
||||||
let ram_size = total_memory as f64; // in B
|
let ram_size = total_memory;
|
||||||
|
|
||||||
// Disk
|
// Disk - updated for sysinfo 0.35
|
||||||
let disk = self.sys.disks().first();
|
|
||||||
// In collect_metrics():
|
|
||||||
let (disk_size, disk_usage, disk_temp) = {
|
let (disk_size, disk_usage, disk_temp) = {
|
||||||
let mut total_size = 0u64;
|
let mut total_size = 0u64;
|
||||||
let mut total_used = 0u64;
|
let mut total_used = 0u64;
|
||||||
let mut temp = 0.0;
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
for disk in self.sys.disks() {
|
for disk in self.sys.disks() {
|
||||||
@@ -390,7 +388,11 @@ impl MetricsCollector {
|
|||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
|
|
||||||
let avg_temp = if count > 0 { temp / count as f32 } else { 0.0 };
|
let avg_temp = if count > 0 {
|
||||||
|
disk_temp / count as f32
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
(size_b, usage, avg_temp as f64)
|
(size_b, usage, avg_temp as f64)
|
||||||
};
|
};
|
||||||
@@ -465,6 +467,16 @@ impl MetricsCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_cpu_temp() -> Option<f32> {
|
fn get_cpu_temp() -> Option<f32> {
|
||||||
|
let sys = System::new_all();
|
||||||
|
|
||||||
|
// Try to get CPU temperature from sysinfo first
|
||||||
|
if let Some(temp) = sys.cpus().first().and_then(|cpu| cpu.get_temperature()) {
|
||||||
|
return Some(temp as f32);
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
/*
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
// Versuche mehrere Methoden der Reihe nach
|
// Versuche mehrere Methoden der Reihe nach
|
||||||
@@ -496,8 +508,8 @@ fn get_cpu_temp() -> Option<f32> {
|
|||||||
|
|
||||||
// 3. Alternative Sysfs-Pfade
|
// 3. Alternative Sysfs-Pfade
|
||||||
let paths = [
|
let paths = [
|
||||||
"/sys/class/hwmon/hwmon*/temp1_input",
|
"/sys/class/hwmon/hwmontemp1_input",
|
||||||
"/sys/class/hwmon/hwmon*/device/temp1_input",
|
"/sys/class/hwmon/hwmondevice/temp1_input",
|
||||||
];
|
];
|
||||||
|
|
||||||
for path_pattern in &paths {
|
for path_pattern in &paths {
|
||||||
@@ -560,8 +572,7 @@ fn get_cpu_temp() -> Option<f32> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
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();
|
||||||
|
Reference in New Issue
Block a user