another cpu temp lib
This commit is contained in:
@@ -18,7 +18,7 @@ chrono = "0.4"
|
||||
nvml-wrapper = "0.10"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { version = "0.3", features = ["winuser"] }
|
||||
winapi = { version = "0.3", features = ["winuser", "pdh", "pdhmsg"] }
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
glob = "0.3"
|
@@ -107,7 +107,7 @@ impl HardwareInfo {
|
||||
.map(|c| c.brand().to_string())
|
||||
.unwrap_or("Unknown CPU".to_string());
|
||||
let cpu_cores = cpus.len() as i32;
|
||||
let ram_gb = (sys.total_memory() as f64) / 1024.0 / 1024.0;
|
||||
let ram_gb = (sys.total_memory() as f64); // in Bytes
|
||||
let gpu_type = Self::detect_gpu_name();
|
||||
let ip_address = local_ip_address::local_ip()?.to_string();
|
||||
|
||||
@@ -514,40 +514,49 @@ fn get_cpu_temp() -> Option<f32> {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
// Windows: OpenHardwareMonitor über WMI abfragen
|
||||
let output = Command::new("wmic")
|
||||
.args(&[
|
||||
"/namespace:\\root\\OpenHardwareMonitor",
|
||||
"path",
|
||||
"Sensor",
|
||||
"get",
|
||||
"Value,Name",
|
||||
"/format:list",
|
||||
])
|
||||
.output()
|
||||
.ok()?;
|
||||
fn get_cpu_temp() -> Option<f32> {
|
||||
use winapi::um::pdh::{
|
||||
PdhAddCounter, PdhCollectQueryData, PdhGetFormattedCounterValue, PdhOpenQuery,
|
||||
PDH_FMT_DOUBLE,
|
||||
};
|
||||
use winapi::um::pdhmsg::PDH_FMT_COUNTERVALUE;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
for line in stdout.lines() {
|
||||
if line.contains("Name=CPU Package") && line.contains("Value=") {
|
||||
if let Some(value) = line.split("Value=").nth(1) {
|
||||
return value.trim().parse::<f32>().ok();
|
||||
}
|
||||
unsafe {
|
||||
let mut query_handle = 0 as u64;
|
||||
if PdhOpenQuery(std::ptr::null_mut(), 0, &mut query_handle) != 0 {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: Standard WMI
|
||||
let output = Command::new("wmic")
|
||||
.args(&["cpu", "get", "Temperature", "/Value"])
|
||||
.output()
|
||||
.ok()?;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
for line in stdout.lines() {
|
||||
if line.starts_with("Temperature=") {
|
||||
return line.replace("Temperature=", "").trim().parse::<f32>().ok();
|
||||
let mut counter_handle = 0 as u64;
|
||||
if PdhAddCounter(
|
||||
query_handle,
|
||||
"\\Processor Information(_Total)\\Temperature",
|
||||
0,
|
||||
&mut counter_handle,
|
||||
) != 0
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
if PdhCollectQueryData(query_handle) != 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut counter_value = PDH_FMT_COUNTERVALUE {
|
||||
CStatus: 0,
|
||||
union: PDH_FMT_DOUBLE { doubleValue: 0.0 },
|
||||
};
|
||||
if PdhGetFormattedCounterValue(
|
||||
counter_handle,
|
||||
PDH_FMT_DOUBLE,
|
||||
std::ptr::null_mut(),
|
||||
&mut counter_value,
|
||||
) != 0
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(counter_value.union.doubleValue as f32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,8 +583,8 @@ fn get_disk_info() -> (f64, f64, f64) {
|
||||
}
|
||||
|
||||
// Berechnungen
|
||||
let size_gb = if count > 0 {
|
||||
total_size as f64 / (1024.0 * 1024.0 * 1024.0)
|
||||
let size_b = if count > 0 {
|
||||
total_size as f64 // in Bytes
|
||||
} else {
|
||||
// Fallback: Versuche df unter Linux
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -598,7 +607,7 @@ fn get_disk_info() -> (f64, f64, f64) {
|
||||
}
|
||||
}
|
||||
}
|
||||
total_size as f64 / (1024.0 * 1024.0 * 1024.0)
|
||||
total_size as f64 // in Bytes
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
@@ -615,7 +624,7 @@ fn get_disk_info() -> (f64, f64, f64) {
|
||||
0.0
|
||||
};
|
||||
|
||||
(size_gb, usage, 0.0) // Disk-Temp bleibt 0.0 ohne spezielle Hardware
|
||||
(size_b, usage, 0.0) // Disk-Temp bleibt 0.0 ohne spezielle Hardware
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
@@ -745,18 +754,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// Test network traffic collection
|
||||
#[test]
|
||||
fn test_network_traffic() {
|
||||
let traffic = get_network_traffic();
|
||||
println!("Network Traffic: {:?}", traffic);
|
||||
|
||||
if let Some((rx, tx)) = traffic {
|
||||
assert!(rx >= 0, "RX bytes should be non-negative");
|
||||
assert!(tx >= 0, "TX bytes should be non-negative");
|
||||
}
|
||||
}
|
||||
|
||||
// Test hardware info collection
|
||||
#[tokio::test]
|
||||
async fn test_hardware_info() {
|
||||
|
Reference in New Issue
Block a user