simplifying network traffic detection
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
use nvml_wrapper::Nvml;
|
||||
use reqwest::{Client, StatusCode};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{error::Error, fs, process::Command, time::Duration};
|
||||
use sysinfo::{Components, Disks, System};
|
||||
use std::{any::Any, error::Error, fs, process::Command, time::Duration};
|
||||
use sysinfo::{Components, Disks, Networks, System};
|
||||
use tokio::time::{interval, sleep, Instant};
|
||||
|
||||
// Windows specific imports
|
||||
@@ -594,7 +594,7 @@ fn get_disk_info() -> (f64, f64, f64) {
|
||||
for component in &components {
|
||||
if let Some(temperature) = component.temperature() {
|
||||
println!(
|
||||
"Component: {}, Temperature: {}°C",
|
||||
"Component_Label: {}, Temperature: {}°C",
|
||||
component.label(),
|
||||
temperature
|
||||
);
|
||||
@@ -647,6 +647,30 @@ fn get_disk_info() -> (f64, f64, f64) {
|
||||
(size_b, usage, 0.0) // Disk-Temp bleibt 0.0 ohne spezielle Hardware
|
||||
}
|
||||
|
||||
fn get_network_traffic() -> Option<(u64, u64)> {
|
||||
let networks = Networks::new_with_refreshed_list();
|
||||
|
||||
if networks.is_empty() {
|
||||
println!("No network interfaces found.");
|
||||
return None;
|
||||
}
|
||||
println!("Found {} network interfaces.", networks.len());
|
||||
|
||||
let mut total_rx = 0;
|
||||
let mut total_tx = 0;
|
||||
|
||||
for (_, data) in &networks {
|
||||
total_rx += data.received();
|
||||
total_tx += data.transmitted();
|
||||
}
|
||||
|
||||
if total_rx == 0 && total_tx == 0 {
|
||||
None
|
||||
} else {
|
||||
Some((total_rx, total_tx))
|
||||
}
|
||||
}
|
||||
/*
|
||||
#[cfg(target_os = "windows")]
|
||||
fn get_network_traffic() -> Option<(u64, u64)> {
|
||||
use std::ptr::null_mut;
|
||||
@@ -710,7 +734,7 @@ fn get_network_traffic() -> Option<(u64, u64)> {
|
||||
}
|
||||
|
||||
Some((rx_total, tx_total))
|
||||
}
|
||||
}*/
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
Reference in New Issue
Block a user