From ea6f45bf2bc6e13d51f35ec7015b78214e44dab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 11 Jan 2025 17:37:58 +0100 Subject: [PATCH] system_stats: add read and written to EWW_DISK --- CHANGELOG.md | 1 + crates/eww/src/config/inbuilt.rs | 2 +- crates/eww/src/config/system_stats.rs | 12 +++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 123475cc..009a5002 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ All notable changes to eww will be listed here, starting at changes since versio - Add `transform-origin-x`/`transform-origin-y` properties to transform widget (By: mario-kr) - Add keyboard support for button presses (By: julianschuler) - Support empty string for safe access operator (By: ModProg) +- Add `read` and `written` to the `EWW_DISK` magic variable (By: bkueng) ## [0.6.0] (21.04.2024) diff --git a/crates/eww/src/config/inbuilt.rs b/crates/eww/src/config/inbuilt.rs index 687fb057..41fd1b7e 100644 --- a/crates/eww/src/config/inbuilt.rs +++ b/crates/eww/src/config/inbuilt.rs @@ -39,7 +39,7 @@ define_builtin_vars! { "EWW_RAM" [2] => || Ok(DynVal::from(get_ram())), // @desc EWW_DISK - Information on on all mounted partitions (Might report inaccurately on some filesystems, like btrfs and zfs) Example: `{EWW_DISK["/"]}` - // @prop { : { name, total, free, used, used_perc } } + // @prop { : { name, total, free, used, used_perc, read, written } } "EWW_DISK" [2] => || Ok(DynVal::from(get_disks())), // @desc EWW_BATTERY - Battery capacity in percent of the main battery diff --git a/crates/eww/src/config/system_stats.rs b/crates/eww/src/config/system_stats.rs index 7e5971ab..d060a07b 100644 --- a/crates/eww/src/config/system_stats.rs +++ b/crates/eww/src/config/system_stats.rs @@ -20,21 +20,25 @@ impl RefreshTime { } static SYSTEM: Lazy> = Lazy::new(|| Mutex::new(System::new())); -static DISKS: Lazy> = Lazy::new(|| Mutex::new(sysinfo::Disks::new_with_refreshed_list())); +static DISKS: Lazy> = + Lazy::new(|| Mutex::new((RefreshTime::new(), sysinfo::Disks::new_with_refreshed_list()))); static COMPONENTS: Lazy> = Lazy::new(|| Mutex::new(sysinfo::Components::new_with_refreshed_list())); static NETWORKS: Lazy> = Lazy::new(|| Mutex::new((RefreshTime::new(), sysinfo::Networks::new_with_refreshed_list()))); pub fn get_disks() -> String { - let mut disks = DISKS.lock().unwrap(); + let (ref mut last_refresh, ref mut disks) = &mut *DISKS.lock().unwrap(); disks.refresh_specifics(true, DiskRefreshKind::everything()); + let elapsed = last_refresh.next_refresh(); + disks .iter() .map(|c| { let total_space = c.total_space(); let available_space = c.available_space(); let used_space = total_space - available_space; + let usage = c.usage(); ( c.mount_point().display().to_string(), @@ -43,7 +47,9 @@ pub fn get_disks() -> String { "total": total_space, "free": available_space, "used": used_space, - "used_perc": (used_space as f32 / total_space as f32) * 100f32 + "used_perc": (used_space as f32 / total_space as f32) * 100f32, + "read": usage.read_bytes as f64 / elapsed.as_secs_f64(), + "written": usage.written_bytes as f64 / elapsed.as_secs_f64(), }), ) })