diskalarm — alerts when a mount fills up
diskalarm is a LightGUI (Python/XFrame) port of the diskalarm utility from util_box: alert when a mount crosses a usage threshold, with a one-line report per mount. Type a percent, press Check, and every real mount is listed as OK or ALARM with its usage percent and free space, plus a summary line. It is one of the 285 apps in util_boxgui, the project recreating util_box utilities as LightGUI apps, each with a screenshot and a walkthrough on the matching LightGUI doc site. The full source is apps/python/diskalarm/diskalarm.py in that repo.
The check for threshold 90 is already run when the app starts, so a plain launch + screenshot shows a real report: 26 mounts on this box, all under 90%, and the summary line says so. The screenshot below is the default state, not a staged one.
The GUI layout

The window is 800×560 and holds five widgets, created with create() + set_prop() and drawn on a single Gtk.DrawingArea:
- Threshold (%): a
GtkLabeland aGtkEntryholding the usage percent that triggers an alarm, pre-filled with90. Click the entry to focus it (a blue outline appears), then type — BackSpace deletes, Escape drops focus. - Check: a
GtkButtonthat checks every real mount at that threshold. Enter re-checks, too. - Hint line: a
GtkLabelexplaining that the alarm fires when a mount's usage reaches the threshold. - Result area: a
GtkTextViewfilling the rest of the window, showing one line per mount —OKorALARM, the mount point, the usage percent, and the free space — plus a summary line. It is read-only — clicking it just drops the entry's focus.
One display compromise is worth knowing about, because it is the only place the GUI's text differs from the CLI's: very long mount paths are shortened. This box is a Docker host, and its overlayfs mounts have 64-hex-character paths; printing one in full would push the percent and free space off the right edge of the window. Paths over 38 characters show the first 18 + an ellipsis + the last 19, so the numbers stay visible. The check itself is untouched — the shortening is display-only, the mount data and the summary line are exactly what the CLI reports:
def _short_mp(mp):
"""Shorten a mount path for display: the full path is kept in
the check, but a 64-hex-char docker overlayfs path would push
the percent and free space off the right edge of the window.
Paths over 38 chars show the first 18 + an ellipsis + the last
19, so the percent, free space, and threshold stay visible."""
if len(mp) <= 38:
return mp
return mp[:18] + "…" + mp[-19:]Two honest limitations, both inherited from how LightGUI draws its widgets with Cairo on one drawing area: there is no native GTK focus, so this app wires focus and typing itself (click to focus, type to edit); and the result area does not really scroll — the text-view scroll bars are drawn, not functional, so a machine with more mounts than fit the window clips at the bottom. A bad threshold shows an error line in the result area instead of argparse's usage error.
The source, in sections
diskalarm.py is about 351 lines. It is modelled on the LightGUI Python examples gtkentry.py, gtkbutton.py and gtktextview.py (and the datecalc app in this repo): widgets are created with create() + set_prop(), drawn on a Gtk.DrawingArea by widget.draw(cr), hit-tested on click, and dispatched through a _HANDLERS table. The check half, though, is not modelled on anything — it is vendored verbatim from the CLI, so the GUI can never drift from it.
The check. check() and human() are copied byte-for-byte from the CLI script into diskalarm.py. It reads /proc/mounts, skips pseudo-filesystems (proc, sysfs, tmpfs, cgroup, and the rest), stats each real mount with os.statvfs, and computes the usage percent from blocks used over blocks total:
def check(threshold, only=None):
rows = []
try:
with open("/proc/mounts") as f:
mounts = [line.split() for line in f]
except OSError:
return rows
for p in mounts:
if len(p) < 3:
continue
mp, fs = p[1], p[2]
if only and mp not in only:
continue
if fs in ("proc", "sysfs", "devpts", "cgroup", "cgroup2", "debugfs",
"securityfs", "pstore", "autofs", "mqueue", "tracefs", "tmpfs"):
continue
try:
st = os.statvfs(mp)
except OSError:
continue
total = st.f_blocks * st.f_frsize
if total == 0:
continue
free = st.f_bfree * st.f_frsize
pct = 100.0 * (total - free) / total
rows.append({"mp": mp, "fs": fs, "pct": pct,
"free": free, "alarm": pct >= threshold})
return rowscompute_text() is the GUI's own half: it parses the threshold entry (empty means 90), runs the vendored check, and formats one line per mount — OK / ALARM, the (possibly shortened) mount point, the percent to one decimal, the human-readable free space, and the threshold — then the summary line: "all 26 mount(s) under 90%" when nothing alarms, or "N mount(s) over T% - free space now!" when something does. The CLI exits 1 when any mount alarms, because it is designed for cron; the GUI stays open and shows the ALARM lines instead of exiting.
The widgets. _build_widgets() creates the five widgets with their design-time geometry, and an _ANCHORS table records each widget's anchor flags so _apply_anchors() can reposition them when the window is resized — recomputed from the design geometry every time, so a resize is idempotent and never drifts. The output area is created already holding the threshold-90 check — that is why the window opens populated. The entry's placeholder text is a hint, not content.
Events. LightGUI draws the widgets with Cairo, so there is no native GTK focus to rely on — the app wires it itself. Clicking the entry focuses it (the draw handler paints a blue outline around the focused widget); typing goes to the focused entry through a window-level key-press handler, which appends printable characters, handles BackSpace and Delete, and re-checks on every keystroke (and on Return). Clicking the Check button re-checks and drops focus. Clicking the output area just drops focus. The dispatch is a small hit-test: the topmost visible widget containing the click gets the event through the _HANDLERS table, and a button release always goes to the widget that got the press, even if the pointer moved off it. main() is the standard LightGUI Python harness: a Gtk.Window titled diskalarm - util_boxgui holding a Gtk.DrawingArea, with the draw, button-press, button-release and resize signals connected, and Gtk.main() running the loop.
Building and running it
There is nothing to build — it is pure Python. Run it with the LightGUI Python package on PYTHONPATH, under a real X server or under Xvfb (display :97 is the one used for this app). It needs python3-gi / gir1.2-gtk-3.0 and the LightGUI Python checkout:
cd apps/python/diskalarm
PYTHONPATH=/root/graphfix-wt/lightgui_python python3 diskalarm.py
# Under Xvfb:
Xvfb :97 -screen 0 1024x768x24 &
DISPLAY=:97 PYTHONPATH=/root/graphfix-wt/lightgui_python python3 diskalarm.pyThe PYTHONPATH above points at the clean graphfix-wt checkout on the build machine — the usual /root/lg-review/lightgui_python checkout is mid-merge as of this writing, so batch 5 was built against the clean one. On your own machine, point it at wherever you cloned LightGUI Python. The window title is diskalarm - util_boxgui.
What the CLI version does differently
Same check, same data, same summary — and the differences are all about the medium. The CLI is diskalarm [--threshold PCT] [--mount MOUNT] [--selftest] and prints to stdout; the GUI shows the report in the result area and never writes to stdout. The GUI has no --mount filter (it checks every mount), and it does not exit 1 on an alarm — it stays open and shows the ALARM lines. The one display difference is the path shortening above; the CLI prints the full 64-hex-character overlayfs paths. Verified against the CLI on the same box: the mount data and the summary line are identical at threshold 90 (all 26 mounts OK) and at threshold 0 (every mount alarms).
See also
- util_boxgui — the project this app belongs to: all 285 apps, with screenshots
- diskalarm.py — the full source
- diskalarm — the util_box CLI this ports
- XFrame widgets
- All 562 Python widgets