Skip to content

Commit

Permalink
system_stats: add read and written to EWW_DISK
Browse files Browse the repository at this point in the history
  • Loading branch information
bkueng committed Jan 11, 2025
1 parent be9070c commit ea6f45b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion crates/eww/src/config/inbuilt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { <mount_point>: { name, total, free, used, used_perc } }
// @prop { <mount_point>: { 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
Expand Down
12 changes: 9 additions & 3 deletions crates/eww/src/config/system_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,25 @@ impl RefreshTime {
}

static SYSTEM: Lazy<Mutex<System>> = Lazy::new(|| Mutex::new(System::new()));
static DISKS: Lazy<Mutex<sysinfo::Disks>> = Lazy::new(|| Mutex::new(sysinfo::Disks::new_with_refreshed_list()));
static DISKS: Lazy<Mutex<(RefreshTime, sysinfo::Disks)>> =
Lazy::new(|| Mutex::new((RefreshTime::new(), sysinfo::Disks::new_with_refreshed_list())));
static COMPONENTS: Lazy<Mutex<sysinfo::Components>> = Lazy::new(|| Mutex::new(sysinfo::Components::new_with_refreshed_list()));
static NETWORKS: Lazy<Mutex<(RefreshTime, sysinfo::Networks)>> =
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(),
Expand All @@ -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(),
}),
)
})
Expand Down

0 comments on commit ea6f45b

Please sign in to comment.