mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-15 01:34:39 +02:00
Set up disk to use heim
This commit is contained in:
parent
153a2590b0
commit
f9b98c71ec
26
src/main.rs
26
src/main.rs
@ -9,11 +9,15 @@ mod window;
|
|||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// Initialize
|
// Initialize
|
||||||
let refresh_interval = 1; // TODO: Make changing this possible!
|
let refresh_interval = 1; // TODO: Make changing this possible!
|
||||||
|
let get_physical_io = false;
|
||||||
let mut sys = System::new();
|
let mut sys = System::new();
|
||||||
|
|
||||||
let mut list_of_timed_processes : Vec<cpu::TimedCPUPackagesStruct> = Vec::new();
|
let mut list_of_timed_processes : Vec<cpu::TimedCPUPackages> = Vec::new();
|
||||||
|
let mut list_of_timed_io : Vec<Vec<disks::TimedIOInfo>> = Vec::new();
|
||||||
|
let mut list_of_timed_physical_io : Vec<Vec<disks::TimedIOInfo>> = Vec::new();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
dbg!("Start data loop...");
|
||||||
sys.refresh_system();
|
sys.refresh_system();
|
||||||
|
|
||||||
// Get data, potentially store?
|
// Get data, potentially store?
|
||||||
@ -22,19 +26,35 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let list_of_disks = disks::get_disk_usage_list().await?;
|
let list_of_disks = disks::get_disk_usage_list().await?;
|
||||||
|
|
||||||
for disk in list_of_disks {
|
for disk in list_of_disks {
|
||||||
println!("{} is mounted on {}: {}/{} free.", disk.name, disk.mount_point, disk.avail_space as f64, disk.total_space as f64);
|
dbg!("{} is mounted on {}: {}/{} free.", disk.name, disk.mount_point, disk.avail_space as f64, disk.total_space as f64);
|
||||||
// TODO: Check if this is valid
|
// TODO: Check if this is valid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_of_timed_io.push(disks::get_io_usage_list(false).await?);
|
||||||
|
list_of_timed_physical_io.push(disks::get_io_usage_list(true).await?);
|
||||||
|
|
||||||
|
if !list_of_timed_io.is_empty() {
|
||||||
|
for io in list_of_timed_io.last().unwrap() {
|
||||||
|
dbg!("IO counter for {} at {:?}: {} writes, {} reads.", &io.mount_point, io.time, io.write_bytes, io.read_bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !list_of_timed_physical_io.is_empty() {
|
||||||
|
for io in list_of_timed_physical_io.last().unwrap() {
|
||||||
|
dbg!("Physical IO counter for {} at {:?}: {} writes, {} reads.", &io.mount_point, io.time, io.write_bytes, io.read_bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
list_of_timed_processes.push(cpu::get_cpu_data_list(&sys));
|
list_of_timed_processes.push(cpu::get_cpu_data_list(&sys));
|
||||||
|
|
||||||
if !list_of_timed_processes.is_empty() {
|
if !list_of_timed_processes.is_empty() {
|
||||||
let current_cpu_time = list_of_timed_processes.last().unwrap().time;
|
let current_cpu_time = list_of_timed_processes.last().unwrap().time;
|
||||||
for cpu in &list_of_timed_processes.last().unwrap().processor_list {
|
for cpu in &list_of_timed_processes.last().unwrap().processor_list {
|
||||||
println!("CPU {} has {}% usage at timestamp {:?}!", cpu.cpu_name, cpu.cpu_usage, current_cpu_time);
|
dbg!("CPU {} has {}% usage at timestamp {:?}!", &cpu.cpu_name, cpu.cpu_usage, current_cpu_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send to drawing module
|
// Send to drawing module
|
||||||
|
dbg!("End data loop...");
|
||||||
window::draw_terminal();
|
window::draw_terminal();
|
||||||
|
|
||||||
// Repeat on interval
|
// Repeat on interval
|
||||||
|
@ -5,12 +5,12 @@ pub struct CPUData {
|
|||||||
pub cpu_usage : u32,
|
pub cpu_usage : u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TimedCPUPackagesStruct {
|
pub struct TimedCPUPackages {
|
||||||
pub processor_list : Vec<CPUData>,
|
pub processor_list : Vec<CPUData>,
|
||||||
pub time : std::time::SystemTime,
|
pub time : std::time::SystemTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cpu_data_list(sys : &System) -> TimedCPUPackagesStruct {
|
pub fn get_cpu_data_list(sys : &System) -> TimedCPUPackages {
|
||||||
let cpu_data = sys.get_processor_list();
|
let cpu_data = sys.get_processor_list();
|
||||||
let mut cpu_vec = Vec::new();
|
let mut cpu_vec = Vec::new();
|
||||||
|
|
||||||
@ -21,12 +21,12 @@ pub fn get_cpu_data_list(sys : &System) -> TimedCPUPackagesStruct {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
TimedCPUPackagesStruct {
|
TimedCPUPackages {
|
||||||
processor_list : cpu_vec,
|
processor_list : cpu_vec,
|
||||||
time : std::time::SystemTime::now(),
|
time : std::time::SystemTime::now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_old_cpu_data() -> bool {
|
pub fn is_cpu_data_old() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -7,29 +7,47 @@ pub struct DiskInfo {
|
|||||||
pub total_space : u64,
|
pub total_space : u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct IOInfo {
|
pub struct TimedIOInfo {
|
||||||
pub name : Box<str>,
|
pub mount_point : Box<str>,
|
||||||
pub read_bytes : u64,
|
pub read_bytes : u64,
|
||||||
pub write_bytes : u64,
|
pub write_bytes : u64,
|
||||||
|
pub time : std::time::SystemTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_io_usage_list() -> Result<Vec<IOInfo>, heim::Error> {
|
pub async fn get_io_usage_list(get_physical : bool) -> Result<Vec<TimedIOInfo>, heim::Error> {
|
||||||
let mut io_list : Vec<IOInfo> = Vec::new();
|
let mut io_list : Vec<TimedIOInfo> = Vec::new();
|
||||||
let mut counters = heim::disk::io_counters();
|
if get_physical {
|
||||||
while let Some(counter) = counters.next().await {
|
let mut physical_counter_stream = heim::disk::io_counters_physical();
|
||||||
dbg!(counter?);
|
while let Some(io) = physical_counter_stream.next().await {
|
||||||
|
let io = io?;
|
||||||
|
io_list.push(TimedIOInfo {
|
||||||
|
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>(),
|
||||||
|
time : std::time::SystemTime::now(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let mut counter_stream = heim::disk::io_counters();
|
||||||
|
while let Some(io) = counter_stream.next().await {
|
||||||
|
let io = io?;
|
||||||
|
io_list.push(TimedIOInfo {
|
||||||
|
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>(),
|
||||||
|
time : std::time::SystemTime::now(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("\n\n--- Per physical disk ---\n");
|
|
||||||
|
|
||||||
let mut counters = heim::disk::io_counters_physical();
|
|
||||||
while let Some(counter) = counters.next().await {
|
|
||||||
dbg!(counter?);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(io_list)
|
Ok(io_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_io_data_old() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_disk_usage_list() -> Result<Vec<DiskInfo>, heim::Error> {
|
pub async fn get_disk_usage_list() -> Result<Vec<DiskInfo>, heim::Error> {
|
||||||
let mut vec_disks : Vec<DiskInfo> = Vec::new();
|
let mut vec_disks : Vec<DiskInfo> = Vec::new();
|
||||||
let mut partitions_stream = heim::disk::partitions_physical();
|
let mut partitions_stream = heim::disk::partitions_physical();
|
||||||
@ -38,15 +56,12 @@ pub async fn get_disk_usage_list() -> Result<Vec<DiskInfo>, heim::Error> {
|
|||||||
let part = part?;
|
let part = part?;
|
||||||
let usage = heim::disk::usage(part.mount_point().to_path_buf()).await?;
|
let usage = heim::disk::usage(part.mount_point().to_path_buf()).await?;
|
||||||
|
|
||||||
println!(
|
vec_disks.push(DiskInfo {
|
||||||
"{:<17} {:<10} {:<10} {:<10} {:<10} {}",
|
avail_space : usage.free().get::<heim_common::units::information::megabyte>(),
|
||||||
part.device().unwrap().to_str().unwrap(),
|
total_space : usage.total().get::<heim_common::units::information::megabyte>(),
|
||||||
usage.total().get::<heim_common::units::information::megabyte>(),
|
mount_point : Box::from(part.mount_point().to_str().unwrap_or("Name Unavailable")),
|
||||||
usage.used().get::<heim_common::units::information::megabyte>(),
|
name : Box::from(part.device().unwrap_or_else(|| std::ffi::OsStr::new("Name Unavailable")).to_str().unwrap_or("Name Unavailable")),
|
||||||
usage.free().get::<heim_common::units::information::megabyte>(),
|
});
|
||||||
part.file_system().as_str(),
|
|
||||||
part.mount_point().to_string_lossy(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(vec_disks)
|
Ok(vec_disks)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user