diff --git a/src/app/mod.rs b/src/app/mod.rs index c4a0eb6..c0d5ab8 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -16,6 +16,8 @@ enum Message { struct State { total_cpu_graph: Graph, cpu_graphs: Vec, + memory_graph: Graph, + swap_graph: Graph, } impl State { @@ -26,6 +28,7 @@ impl State { stream::channel(1, async |mut sender| { let mut sys = sysinfo::System::new(); let refreshes = sysinfo::RefreshKind::nothing() + .with_memory(sysinfo::MemoryRefreshKind::everything()) .with_cpu(sysinfo::CpuRefreshKind::nothing().with_cpu_usage()); sys.refresh_specifics(refreshes); @@ -47,6 +50,14 @@ impl State { self.total_cpu_graph.update(snapshot.cpu_total); self.total_cpu_graph.cache.clear(); + self.memory_graph + .update(snapshot.memory as f32 / snapshot.memory_total as f32 * 100.); + self.memory_graph.cache.clear(); + + self.swap_graph + .update(snapshot.swap as f32 / snapshot.swap_total as f32 * 100.); + self.swap_graph.cache.clear(); + if self.cpu_graphs.len() != snapshot.cpus.len() { self.cpu_graphs = snapshot .cpus @@ -66,18 +77,32 @@ impl State { Task::none() } fn view(&self) -> Element<'_, Message, Theme, Renderer> { - widget::row([ - widget::Canvas::new(&self.total_cpu_graph) - .width(Length::Fill) + widget::column([ + widget::row([ + widget::Canvas::new(&self.total_cpu_graph) + .width(Length::Fill) + .height(Length::Fill) + .into(), + widget::grid( + self.cpu_graphs + .iter() + .map(|graph| widget::Canvas::new(graph).into()), + ) + .columns(2) .height(Length::Fill) .into(), - widget::grid( - self.cpu_graphs - .iter() - .map(|graph| widget::Canvas::new(graph).into()), - ) - .columns(2) - .height(Length::Fill) + ]) + .into(), + widget::row([ + widget::canvas(&self.memory_graph) + .width(Length::Fill) + .height(Length::Fill) + .into(), + widget::canvas(&self.swap_graph) + .width(Length::Fill) + .height(Length::Fill) + .into(), + ]) .into(), ]) .into() diff --git a/src/sysinfo_snapshot.rs b/src/sysinfo_snapshot.rs index cb55f06..340a215 100644 --- a/src/sysinfo_snapshot.rs +++ b/src/sysinfo_snapshot.rs @@ -2,6 +2,11 @@ pub struct SysinfoSnapshot { pub cpu_total: f32, pub cpus: Vec, + + pub memory: u64, + pub memory_total: u64, + pub swap: u64, + pub swap_total: u64, } impl From<&sysinfo::System> for SysinfoSnapshot { @@ -9,6 +14,11 @@ impl From<&sysinfo::System> for SysinfoSnapshot { Self { cpu_total: value.global_cpu_usage(), cpus: value.cpus().iter().map(|cpu| cpu.cpu_usage()).collect(), + + memory: value.used_memory(), + memory_total: value.total_memory(), + swap: value.used_swap(), + swap_total: value.total_swap(), } } }