A storage monitoring Waybar module. Displays a summary of disk usage for each mounted fs.
Reads currently mounted filesystems from /proc/mounts, and outputs a summary in a Waybar-compatible JSON format.
Updates every 20sec.
Requires Zig 0.15.x.
Depends on libc for sys/statvfs.h.
zig build -Doptimize=ReleaseFastI prefer ReleaseFast since it's running as part of my desktop, though you can use whatever safety mode you prefer.
I've added a no-bin option in build.zig to enable incremental build/filesystem watching without emitting a binary, to catch compiler errors immediately upon file save:
zig build -Dno-bin -fincremental --watch --debounce 100Build for valgrind/massif:
zig build -Doptimize=ReleaseFast -Dcpu=baselineThen run under i.e. massif:
valgrind --tool=massif ./zig-out/bin/disk-usage-monitor-waybarNote: You must use the std.heap.c_allocator (or heap.raw_c_allocator) to profile a Zig executable under valgrind/massif, otherwise massif will report zero heap usage/incorrect leak results.
Executable comes out to ~380KiB depending on target. Peak heap usage around 13KiB with ~10 mounted filesystems.
After compiling, place the executable somewhere that's in Waybar's PATH, I prefer to create a bin directory at either ~/bin/ or ~/.config/bin/ - wherever you put your dotfile-related executables is fine.
First, add it to your waybar config and configure however you want it. An example is included in example-configs/bar.conf.
Module output includes some CSS class modifiers that Waybar will pull, so you can optionally style the widget with i.e. different colors based on level of disk usage - .low, .medium, .high, and .critical.
Example stylesheet applying various colors mapped to usage level:
/* Default color */
#custom-disk-usage {
color: @darkForeground1;
}
#custom-disk-usage.low {
color: @darkStrongGreen;
}
#custom-disk-usage.medium {
color: @darkStrongYellow;
}
#custom-disk-usage.high {
color: @darkMutedRed;
}
#custom-disk-usage.critical, #custom-disk-usage.err {
color: @darkStrongRed;
}