summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2020-02-09 22:11:03 -0500
committerClementTsang <cjhtsang@uwaterloo.ca>2020-02-09 22:11:03 -0500
commit1ac6cdde2faf802b7af288ecd93b620eab9a437a (patch)
tree09be92ebe32aaa40b8625df5c6347bfdc9de0548 /src
parent5dd22c6c8958ff726c11607abd53cf7151f0c919 (diff)
Update sysinfo, add total network to windows/linux.
Diffstat (limited to 'src')
-rw-r--r--src/app/data_harvester.rs5
-rw-r--r--src/app/data_harvester/cpu.rs4
-rw-r--r--src/app/data_harvester/network.rs46
-rw-r--r--src/app/data_harvester/processes.rs2
-rw-r--r--src/app/data_harvester/temperature.rs2
-rw-r--r--src/main.rs4
6 files changed, 30 insertions, 33 deletions
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs
index 9ad176b5..4065f7ed 100644
--- a/src/app/data_harvester.rs
+++ b/src/app/data_harvester.rs
@@ -75,7 +75,7 @@ impl Default for DataState {
fn default() -> Self {
DataState {
data: Data::default(),
- sys: System::new(),
+ sys: System::new_all(),
prev_pid_stats: HashMap::new(),
prev_idle: 0_f64,
prev_non_idle: 0_f64,
@@ -96,7 +96,6 @@ impl DataState {
}
pub fn init(&mut self) {
- self.sys.refresh_all();
self.mem_total_kb = self.sys.get_total_memory();
futures::executor::block_on(self.update_data());
std::thread::sleep(std::time::Duration::from_millis(250));
@@ -109,7 +108,7 @@ impl DataState {
if !cfg!(target_os = "linux") {
// For now, might be just windows tbh
self.sys.refresh_processes();
- self.sys.refresh_network();
+ self.sys.refresh_networks();
}
let current_instant = std::time::Instant::now();
diff --git a/src/app/data_harvester/cpu.rs b/src/app/data_harvester/cpu.rs
index 136a36dd..8f45e191 100644
--- a/src/app/data_harvester/cpu.rs
+++ b/src/app/data_harvester/cpu.rs
@@ -9,13 +9,13 @@ pub struct CPUData {
pub type CPUHarvest = Vec<CPUData>;
pub fn get_cpu_data_list(sys: &System) -> CPUHarvest {
- let cpu_data = sys.get_processor_list();
+ let cpu_data = sys.get_processors();
let mut cpu_vec = Vec::new();
for cpu in cpu_data {
cpu_vec.push(CPUData {
cpu_name: cpu.get_name().to_string(),
- cpu_usage: f64::from(cpu.get_cpu_usage()) * 100_f64,
+ cpu_usage: f64::from(cpu.get_cpu_usage()),
});
}
diff --git a/src/app/data_harvester/network.rs b/src/app/data_harvester/network.rs
index a2aea768..ad06368f 100644
--- a/src/app/data_harvester/network.rs
+++ b/src/app/data_harvester/network.rs
@@ -23,40 +23,38 @@ pub async fn get_network_data(
sys: &System, prev_net_access_time: &Instant, prev_net_rx: &mut u64, prev_net_tx: &mut u64,
curr_time: &Instant,
) -> NetworkHarvest {
- // FIXME: [WIN] Track current total bytes... also is this accurate?
+ let mut io_data = net::io_counters();
+ let mut total_rx: u64 = 0;
+ let mut total_tx: u64 = 0;
+
if cfg!(target_os = "windows") {
- let network_data = sys.get_network();
- NetworkHarvest {
- rx: network_data.get_income(),
- tx: network_data.get_outcome(),
- total_rx: 0,
- total_tx: 0,
+ let networks = sys.get_networks();
+ for (_, network) in networks {
+ total_rx += network.get_total_income();
+ total_tx += network.get_total_outcome();
}
} else {
- let mut io_data = net::io_counters();
- let mut total_rx: u64 = 0;
- let mut total_tx: u64 = 0;
-
while let Some(io) = io_data.next().await {
if let Ok(io) = io {
total_rx += io.bytes_recv().get::<byte>();
total_tx += io.bytes_sent().get::<byte>();
}
}
- let elapsed_time = curr_time
- .duration_since(*prev_net_access_time)
- .as_secs_f64();
+ }
- let rx = ((total_rx - *prev_net_rx) as f64 / elapsed_time) as u64;
- let tx = ((total_tx - *prev_net_tx) as f64 / elapsed_time) as u64;
+ let elapsed_time = curr_time
+ .duration_since(*prev_net_access_time)
+ .as_secs_f64();
- *prev_net_rx = total_rx;
- *prev_net_tx = total_tx;
- NetworkHarvest {
- rx,
- tx,
- total_rx,
- total_tx,
- }
+ let rx = ((total_rx - *prev_net_rx) as f64 / elapsed_time) as u64;
+ let tx = ((total_tx - *prev_net_tx) as f64 / elapsed_time) as u64;
+
+ *prev_net_rx = total_rx;
+ *prev_net_tx = total_tx;
+ NetworkHarvest {
+ rx,
+ tx,
+ total_rx,
+ total_tx,
}
}
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs
index f4b49f96..80c81ba2 100644
--- a/src/app/data_harvester/processes.rs
+++ b/src/app/data_harvester/processes.rs
@@ -231,7 +231,7 @@ pub fn get_sorted_processes_list(
error!("Result: {:?}", cpu_calc.err());
}
} else {
- let process_hashmap = sys.get_process_list();
+ let process_hashmap = sys.get_processes();
for process_val in process_hashmap.values() {
let name = if process_val.name().is_empty() {
let process_cmd = process_val.cmd();
diff --git a/src/app/data_harvester/temperature.rs b/src/app/data_harvester/temperature.rs
index 77ffa4d6..a0c468a3 100644
--- a/src/app/data_harvester/temperature.rs
+++ b/src/app/data_harvester/temperature.rs
@@ -50,7 +50,7 @@ pub async fn get_temperature_data(
}
}
} else {
- let sensor_data = sys.get_components_list();
+ let sensor_data = sys.get_components();
for component in sensor_data {
temperature_vec.push(TempHarvest {
component_name: component.get_label().to_string(),
diff --git a/src/main.rs b/src/main.rs
index f0426430..1ef216d8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -361,8 +361,8 @@ fn main() -> error::Result<()> {
}
}
futures::executor::block_on(data_state.update_data());
- tx.send(Event::Update(Box::from(data_state.data.clone())))
- .unwrap(); // TODO: [UNWRAP] Might be required, it's in a closure and idk how to deal with it
+ let event = Event::Update(Box::from(data_state.data.clone()));
+ tx.send(event).unwrap();
thread::sleep(Duration::from_millis(update_rate_in_milliseconds as u64));
}
});