diff options
author | ClementTsang <clementjhtsang@gmail.com> | 2019-09-16 16:18:42 -0400 |
---|---|---|
committer | ClementTsang <clementjhtsang@gmail.com> | 2019-09-16 16:18:42 -0400 |
commit | 43ac5c339971e27261f87aea79b56d7ac4159cea (patch) | |
tree | 09280e39fd30b1f2f71b2713d44833b0973f1648 /src/app | |
parent | 6327ba2c7b38ba32cefa258b5051525e0c7d4650 (diff) |
Added reads and writes for disk.
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/data_collection.rs | 21 | ||||
-rw-r--r-- | src/app/data_collection/disks.rs | 37 | ||||
-rw-r--r-- | src/app/data_collection/processes.rs | 2 |
3 files changed, 38 insertions, 22 deletions
diff --git a/src/app/data_collection.rs b/src/app/data_collection.rs index 4e45b719..c292fb94 100644 --- a/src/app/data_collection.rs +++ b/src/app/data_collection.rs @@ -80,6 +80,11 @@ impl DataState { self.sys.refresh_system(); self.sys.refresh_network(); + if !cfg!(target_os = "linux") { + // For now, might be just windows tbh + self.sys.refresh_processes(); + } + // What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update! push_if_valid(&network::get_network_data(&self.sys), &mut self.data.network); push_if_valid(&cpu::get_cpu_data_list(&self.sys), &mut self.data.list_of_cpu_packages); @@ -94,7 +99,7 @@ impl DataState { set_if_valid(&disks::get_disk_usage_list().await, &mut self.data.list_of_disks); push_if_valid(&disks::get_io_usage_list(false).await, &mut self.data.list_of_io); - push_if_valid(&disks::get_io_usage_list(true).await, &mut self.data.list_of_physical_io); + //push_if_valid(&disks::get_io_usage_list(true).await, &mut self.data.list_of_physical_io); set_if_valid(&temperature::get_temperature_data(&self.temperature_type).await, &mut self.data.list_of_temperature_sensor); if self.first_run { @@ -144,13 +149,13 @@ impl DataState { .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds) .collect::<Vec<_>>(); - self.data.list_of_physical_io = self - .data - .list_of_physical_io - .iter() - .cloned() - .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds) - .collect::<Vec<_>>(); + // self.data.list_of_physical_io = self + // .data + // .list_of_physical_io + // .iter() + // .cloned() + // .filter(|entry| current_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds) + // .collect::<Vec<_>>(); debug!("End updating..."); } diff --git a/src/app/data_collection/disks.rs b/src/app/data_collection/disks.rs index 4e532b8a..10349a61 100644 --- a/src/app/data_collection/disks.rs +++ b/src/app/data_collection/disks.rs @@ -10,7 +10,7 @@ pub struct DiskData { pub total_space : u64, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct IOData { pub mount_point : Box<str>, pub read_bytes : u64, @@ -19,37 +19,46 @@ pub struct IOData { #[derive(Clone)] pub struct IOPackage { - pub io_list : Vec<IOData>, + pub io_hash : std::collections::HashMap<String, IOData>, pub instant : Instant, } +// TODO: This is total --- we have to change the calculation to PER SECOND! pub async fn get_io_usage_list(get_physical : bool) -> Result<IOPackage, heim::Error> { - let mut io_list : Vec<IOData> = Vec::new(); + let mut io_hash : std::collections::HashMap<String, IOData> = std::collections::HashMap::new(); if get_physical { let mut physical_counter_stream = heim::disk::io_counters_physical(); while let Some(io) = physical_counter_stream.next().await { let io = io?; - io_list.push(IOData { - mount_point : Box::from(io.device_name().to_str().unwrap_or("Name Unavailable")), - read_bytes : io.read_bytes().get::<heim_common::units::information::megabyte>(), - write_bytes : io.write_bytes().get::<heim_common::units::information::megabyte>(), - }) + let mount_point = io.device_name().to_str().unwrap_or("Name Unavailable"); + io_hash.insert( + mount_point.to_string(), + IOData { + mount_point : Box::from(mount_point), + read_bytes : io.read_bytes().get::<heim_common::units::information::megabyte>(), + write_bytes : io.write_bytes().get::<heim_common::units::information::megabyte>(), + }, + ); } } else { let mut counter_stream = heim::disk::io_counters(); while let Some(io) = counter_stream.next().await { let io = io?; - io_list.push(IOData { - mount_point : Box::from(io.device_name().to_str().unwrap_or("Name Unavailable")), - read_bytes : io.read_bytes().get::<heim_common::units::information::megabyte>(), - write_bytes : io.write_bytes().get::<heim_common::units::information::megabyte>(), - }) + let mount_point = io.device_name().to_str().unwrap_or("Name Unavailable"); + io_hash.insert( + mount_point.to_string(), + IOData { + mount_point : Box::from(mount_point), + read_bytes : io.read_bytes().get::<heim_common::units::information::byte>(), + write_bytes : io.write_bytes().get::<heim_common::units::information::byte>(), + }, + ); } } Ok(IOPackage { - io_list, + io_hash, instant : Instant::now(), }) } diff --git a/src/app/data_collection/processes.rs b/src/app/data_collection/processes.rs index e688b560..cb9d4516 100644 --- a/src/app/data_collection/processes.rs +++ b/src/app/data_collection/processes.rs @@ -196,6 +196,8 @@ pub async fn get_sorted_processes_list( } else if cfg!(target_os = "windows") { // Windows + + // TODO: DO NOT USE HEIM! let mut process_stream = heim::process::processes().map_ok(non_linux_cpu_usage).try_buffer_unordered(std::usize::MAX); let mut process_vector : Vec<ProcessData> = Vec::new(); |