feat: memory and swap graphs
the values are in the SysinfoSnapshot verbatim, in case they might be displayed in another way (textually)
This commit is contained in:
parent
374cbd546d
commit
d068d110e2
2 changed files with 45 additions and 10 deletions
|
|
@ -16,6 +16,8 @@ enum Message {
|
||||||
struct State {
|
struct State {
|
||||||
total_cpu_graph: Graph,
|
total_cpu_graph: Graph,
|
||||||
cpu_graphs: Vec<Graph>,
|
cpu_graphs: Vec<Graph>,
|
||||||
|
memory_graph: Graph,
|
||||||
|
swap_graph: Graph,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
|
@ -26,6 +28,7 @@ impl State {
|
||||||
stream::channel(1, async |mut sender| {
|
stream::channel(1, async |mut sender| {
|
||||||
let mut sys = sysinfo::System::new();
|
let mut sys = sysinfo::System::new();
|
||||||
let refreshes = sysinfo::RefreshKind::nothing()
|
let refreshes = sysinfo::RefreshKind::nothing()
|
||||||
|
.with_memory(sysinfo::MemoryRefreshKind::everything())
|
||||||
.with_cpu(sysinfo::CpuRefreshKind::nothing().with_cpu_usage());
|
.with_cpu(sysinfo::CpuRefreshKind::nothing().with_cpu_usage());
|
||||||
|
|
||||||
sys.refresh_specifics(refreshes);
|
sys.refresh_specifics(refreshes);
|
||||||
|
|
@ -47,6 +50,14 @@ impl State {
|
||||||
self.total_cpu_graph.update(snapshot.cpu_total);
|
self.total_cpu_graph.update(snapshot.cpu_total);
|
||||||
self.total_cpu_graph.cache.clear();
|
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() {
|
if self.cpu_graphs.len() != snapshot.cpus.len() {
|
||||||
self.cpu_graphs = snapshot
|
self.cpu_graphs = snapshot
|
||||||
.cpus
|
.cpus
|
||||||
|
|
@ -66,18 +77,32 @@ impl State {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
fn view(&self) -> Element<'_, Message, Theme, Renderer> {
|
fn view(&self) -> Element<'_, Message, Theme, Renderer> {
|
||||||
widget::row([
|
widget::column([
|
||||||
widget::Canvas::new(&self.total_cpu_graph)
|
widget::row([
|
||||||
.width(Length::Fill)
|
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)
|
.height(Length::Fill)
|
||||||
.into(),
|
.into(),
|
||||||
widget::grid(
|
])
|
||||||
self.cpu_graphs
|
.into(),
|
||||||
.iter()
|
widget::row([
|
||||||
.map(|graph| widget::Canvas::new(graph).into()),
|
widget::canvas(&self.memory_graph)
|
||||||
)
|
.width(Length::Fill)
|
||||||
.columns(2)
|
.height(Length::Fill)
|
||||||
.height(Length::Fill)
|
.into(),
|
||||||
|
widget::canvas(&self.swap_graph)
|
||||||
|
.width(Length::Fill)
|
||||||
|
.height(Length::Fill)
|
||||||
|
.into(),
|
||||||
|
])
|
||||||
.into(),
|
.into(),
|
||||||
])
|
])
|
||||||
.into()
|
.into()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@
|
||||||
pub struct SysinfoSnapshot {
|
pub struct SysinfoSnapshot {
|
||||||
pub cpu_total: f32,
|
pub cpu_total: f32,
|
||||||
pub cpus: Vec<f32>,
|
pub cpus: Vec<f32>,
|
||||||
|
|
||||||
|
pub memory: u64,
|
||||||
|
pub memory_total: u64,
|
||||||
|
pub swap: u64,
|
||||||
|
pub swap_total: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&sysinfo::System> for SysinfoSnapshot {
|
impl From<&sysinfo::System> for SysinfoSnapshot {
|
||||||
|
|
@ -9,6 +14,11 @@ impl From<&sysinfo::System> for SysinfoSnapshot {
|
||||||
Self {
|
Self {
|
||||||
cpu_total: value.global_cpu_usage(),
|
cpu_total: value.global_cpu_usage(),
|
||||||
cpus: value.cpus().iter().map(|cpu| cpu.cpu_usage()).collect(),
|
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(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue