simplifying network traffic detection
This commit is contained in:
@@ -5,8 +5,8 @@
|
|||||||
use nvml_wrapper::Nvml;
|
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::{any::Any, error::Error, fs, process::Command, time::Duration};
|
||||||
use sysinfo::{Components, Disks, System};
|
use sysinfo::{Components, Disks, Networks, System};
|
||||||
use tokio::time::{interval, sleep, Instant};
|
use tokio::time::{interval, sleep, Instant};
|
||||||
|
|
||||||
// Windows specific imports
|
// Windows specific imports
|
||||||
@@ -594,7 +594,7 @@ fn get_disk_info() -> (f64, f64, f64) {
|
|||||||
for component in &components {
|
for component in &components {
|
||||||
if let Some(temperature) = component.temperature() {
|
if let Some(temperature) = component.temperature() {
|
||||||
println!(
|
println!(
|
||||||
"Component: {}, Temperature: {}°C",
|
"Component_Label: {}, Temperature: {}°C",
|
||||||
component.label(),
|
component.label(),
|
||||||
temperature
|
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
|
(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")]
|
#[cfg(target_os = "windows")]
|
||||||
fn get_network_traffic() -> Option<(u64, u64)> {
|
fn get_network_traffic() -> Option<(u64, u64)> {
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
@@ -710,7 +734,7 @@ fn get_network_traffic() -> Option<(u64, u64)> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Some((rx_total, tx_total))
|
Some((rx_total, tx_total))
|
||||||
}
|
}*/
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn Error>> {
|
async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
Reference in New Issue
Block a user