Added interval, disk tracking.

This commit is contained in:
ClementTsang 2019-09-06 00:05:50 -04:00
parent 243742de2a
commit 832d32700e
10 changed files with 62 additions and 19 deletions

View file

@ -26,7 +26,7 @@ A gotop clone, written in Rust. Mostly done in an effort to learn Rust, while a
* Definitely keybinds
* Filtering in processing
* Filtering in processes along with sorting
* See if current disk activity is possible to do/graph?

View file

@ -8,8 +8,10 @@
* Write cursive display
* Charting?
* Keybindings
* Theming
* Efficiency!!! Reuse hashmaps for example.
* Efficiency!!! Make sure no wasted hashmaps, use references, etc.

View file

@ -3,8 +3,29 @@ mod widgets;
use widgets::{cpu, disks, mem, network, processes, temperature};
fn main() {
// Initialize
let mut system = System::new();
system.refresh_all();
//processes::draw_sorted_processes(processes::ProcessSorting::NAME, true, &system);
disks::draw_disk_usage_data(&system);
let refresh_interval = 10;
// Start loop (TODO: do that)
loop {
system.refresh_system();
system.refresh_processes();
system.refresh_disk_list();
system.refresh_disks();
system.refresh_network();
// Get data, potentially store?
//let list_of_processes = processes::get_sorted_processes_list(processes::ProcessSorting::NAME, true, &system);
let list_of_disks = disks::get_disk_usage_list(&system);
for disk in list_of_disks {
println!("{} is mounted on {}: {}/{}", disk.name, disk.mount_point, disk.avail_space, disk.total_space);
}
// Draw using cursive
// Repeat on interval
std::thread::sleep(std::time::Duration::from_secs(refresh_interval));
}
}

View file

@ -1,3 +1,9 @@
struct TimedCPUData<'a> {
cpu_name: &'a str,
cpu_usage: f32,
time: std::time::Duration,
}
fn get_timestamped_cpu_data() {}
fn draw_cpu_data() {}
pub fn get_cpu_data_list() {}

View file

@ -1,11 +1,24 @@
use sysinfo::{System, SystemExt, DiskExt};
use sysinfo::{System, SystemExt, Disk, DiskExt};
fn get_timestamped_disk_data() {}
pub fn draw_disk_usage_data(sys: &System) {
let list_of_disks = sys.get_disks();
for disk in list_of_disks {
println!("Disk: Total size: {}, used: {}, disk: {}, mount: {}", disk.get_total_space(), disk.get_total_space() - disk.get_available_space(), disk.get_name().to_str().unwrap(), disk.get_mount_point().to_str().unwrap());
}
pub struct DiskInfo<'a> {
pub name: &'a str,
pub mount_point: &'a str,
pub avail_space: u64,
pub total_space: u64,
}
pub fn get_disk_usage_list(sys: &System) -> Vec<DiskInfo> {
let result_disks = sys.get_disks();
let mut vec_disks : Vec<DiskInfo> = Vec::new();
for disk in result_disks {
vec_disks.push(DiskInfo {
name: disk.get_name().to_str().unwrap(),
mount_point: disk.get_mount_point().to_str().unwrap(),
avail_space: disk.get_available_space(),
total_space: disk.get_total_space(),
});
}
vec_disks
}

View file

@ -1,3 +1,3 @@
fn get_timestamped_ram_data() {}
fn draw_ram_data() {}
pub fn get_ram_data_list() {}

View file

@ -1,3 +1,3 @@
fn get_timestamped_network_data() {}
fn draw_network_data() {}
fn get_network_data_list() {}

View file

@ -50,7 +50,7 @@ fn get_ordering<T: std::cmp::PartialOrd>(a_val: T, b_val: T, reverse_order: bool
}
}
pub fn draw_sorted_processes(sorting_method: ProcessSorting, reverse_order: bool, sys: &System) {
pub fn get_sorted_processes_list(sorting_method: ProcessSorting, reverse_order: bool, sys: &System) {
let process_hashmap = sys.get_process_list();
// TODO: Evaluate whether this is too slow!

View file

@ -1,3 +1,3 @@
fn get_timestamped_temperature() {}
fn draw_temperatures() {}
fn get_temps_list() {}

1
src/window/mod.rs Normal file
View file

@ -0,0 +1 @@
use cursive::Cursive;