mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-23 04:33:10 +00:00
Update sysinfo, add total network to windows/linux.
This commit is contained in:
parent
5dd22c6c89
commit
1ac6cdde2f
7 changed files with 32 additions and 35 deletions
|
@ -25,11 +25,11 @@ chrono = "0.4.10"
|
||||||
clap = "2.33.0"
|
clap = "2.33.0"
|
||||||
fern = "0.5.9"
|
fern = "0.5.9"
|
||||||
futures-timer = "3.0.1"
|
futures-timer = "3.0.1"
|
||||||
futures = "0.3.3"
|
futures = "0.3.4"
|
||||||
heim = "0.0.9"
|
heim = "0.0.9"
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
regex = "1.3.4"
|
regex = "1.3.4"
|
||||||
sysinfo = "0.10.5"
|
sysinfo = "0.11"
|
||||||
tokio = "0.2.11"
|
tokio = "0.2.11"
|
||||||
winapi = "0.3.8"
|
winapi = "0.3.8"
|
||||||
crossterm = "0.14"
|
crossterm = "0.14"
|
||||||
|
|
|
@ -75,7 +75,7 @@ impl Default for DataState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
DataState {
|
DataState {
|
||||||
data: Data::default(),
|
data: Data::default(),
|
||||||
sys: System::new(),
|
sys: System::new_all(),
|
||||||
prev_pid_stats: HashMap::new(),
|
prev_pid_stats: HashMap::new(),
|
||||||
prev_idle: 0_f64,
|
prev_idle: 0_f64,
|
||||||
prev_non_idle: 0_f64,
|
prev_non_idle: 0_f64,
|
||||||
|
@ -96,7 +96,6 @@ impl DataState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(&mut self) {
|
pub fn init(&mut self) {
|
||||||
self.sys.refresh_all();
|
|
||||||
self.mem_total_kb = self.sys.get_total_memory();
|
self.mem_total_kb = self.sys.get_total_memory();
|
||||||
futures::executor::block_on(self.update_data());
|
futures::executor::block_on(self.update_data());
|
||||||
std::thread::sleep(std::time::Duration::from_millis(250));
|
std::thread::sleep(std::time::Duration::from_millis(250));
|
||||||
|
@ -109,7 +108,7 @@ impl DataState {
|
||||||
if !cfg!(target_os = "linux") {
|
if !cfg!(target_os = "linux") {
|
||||||
// For now, might be just windows tbh
|
// For now, might be just windows tbh
|
||||||
self.sys.refresh_processes();
|
self.sys.refresh_processes();
|
||||||
self.sys.refresh_network();
|
self.sys.refresh_networks();
|
||||||
}
|
}
|
||||||
|
|
||||||
let current_instant = std::time::Instant::now();
|
let current_instant = std::time::Instant::now();
|
||||||
|
|
|
@ -9,13 +9,13 @@ pub struct CPUData {
|
||||||
pub type CPUHarvest = Vec<CPUData>;
|
pub type CPUHarvest = Vec<CPUData>;
|
||||||
|
|
||||||
pub fn get_cpu_data_list(sys: &System) -> CPUHarvest {
|
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();
|
let mut cpu_vec = Vec::new();
|
||||||
|
|
||||||
for cpu in cpu_data {
|
for cpu in cpu_data {
|
||||||
cpu_vec.push(CPUData {
|
cpu_vec.push(CPUData {
|
||||||
cpu_name: cpu.get_name().to_string(),
|
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()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,26 +23,25 @@ pub async fn get_network_data(
|
||||||
sys: &System, prev_net_access_time: &Instant, prev_net_rx: &mut u64, prev_net_tx: &mut u64,
|
sys: &System, prev_net_access_time: &Instant, prev_net_rx: &mut u64, prev_net_tx: &mut u64,
|
||||||
curr_time: &Instant,
|
curr_time: &Instant,
|
||||||
) -> NetworkHarvest {
|
) -> NetworkHarvest {
|
||||||
// FIXME: [WIN] Track current total bytes... also is this accurate?
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let mut io_data = net::io_counters();
|
let mut io_data = net::io_counters();
|
||||||
let mut total_rx: u64 = 0;
|
let mut total_rx: u64 = 0;
|
||||||
let mut total_tx: u64 = 0;
|
let mut total_tx: u64 = 0;
|
||||||
|
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
let networks = sys.get_networks();
|
||||||
|
for (_, network) in networks {
|
||||||
|
total_rx += network.get_total_income();
|
||||||
|
total_tx += network.get_total_outcome();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
while let Some(io) = io_data.next().await {
|
while let Some(io) = io_data.next().await {
|
||||||
if let Ok(io) = io {
|
if let Ok(io) = io {
|
||||||
total_rx += io.bytes_recv().get::<byte>();
|
total_rx += io.bytes_recv().get::<byte>();
|
||||||
total_tx += io.bytes_sent().get::<byte>();
|
total_tx += io.bytes_sent().get::<byte>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let elapsed_time = curr_time
|
let elapsed_time = curr_time
|
||||||
.duration_since(*prev_net_access_time)
|
.duration_since(*prev_net_access_time)
|
||||||
.as_secs_f64();
|
.as_secs_f64();
|
||||||
|
@ -59,4 +58,3 @@ pub async fn get_network_data(
|
||||||
total_tx,
|
total_tx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -231,7 +231,7 @@ pub fn get_sorted_processes_list(
|
||||||
error!("Result: {:?}", cpu_calc.err());
|
error!("Result: {:?}", cpu_calc.err());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let process_hashmap = sys.get_process_list();
|
let process_hashmap = sys.get_processes();
|
||||||
for process_val in process_hashmap.values() {
|
for process_val in process_hashmap.values() {
|
||||||
let name = if process_val.name().is_empty() {
|
let name = if process_val.name().is_empty() {
|
||||||
let process_cmd = process_val.cmd();
|
let process_cmd = process_val.cmd();
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub async fn get_temperature_data(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let sensor_data = sys.get_components_list();
|
let sensor_data = sys.get_components();
|
||||||
for component in sensor_data {
|
for component in sensor_data {
|
||||||
temperature_vec.push(TempHarvest {
|
temperature_vec.push(TempHarvest {
|
||||||
component_name: component.get_label().to_string(),
|
component_name: component.get_label().to_string(),
|
||||||
|
|
|
@ -361,8 +361,8 @@ fn main() -> error::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
futures::executor::block_on(data_state.update_data());
|
futures::executor::block_on(data_state.update_data());
|
||||||
tx.send(Event::Update(Box::from(data_state.data.clone())))
|
let event = 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
|
tx.send(event).unwrap();
|
||||||
thread::sleep(Duration::from_millis(update_rate_in_milliseconds as u64));
|
thread::sleep(Duration::from_millis(update_rate_in_milliseconds as u64));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue