go-powerd
- #Go
- #Netlink
- #sysfs
- #Linux
Netlink-driven battery daemon, ~12MB RSS, static binary with systemd integration.
Why this exists
Most battery applets either pull in heavy GUI stacks or poll sysfs on a timer. On a minimalist Sway or i3 setup, you want something that stays out of the way: a small static binary, a readable tray icon, and honest integration with how Linux actually reports power state.
go-powerd is a system-tray daemon (or a one-shot stdout mode for Waybar and Polybar) that aggregates multi-battery laptops, surfaces per-pack health in the tooltip, and runs policy actions when thresholds are crossed.
How it monitors
Primary path is Netlink uevents — reactive kernel notifications when power supply state changes. A 60-second fail-safe ticker backs that up so a missed event does not leave the UI stale indefinitely. That is hybrid monitoring, not pure event-driven absolutism.
Battery data is read from sysfs via a parser that scans lines manually with zero heap allocation on the hot path.
Architecture
| Package | Role |
|---|---|
internal/netlink |
Low-level reactive kernel events via AF_NETLINK |
internal/battery |
Direct sysfs parsing |
internal/policy |
FSM for notify/suspend thresholds with hysteresis |
internal/debounce |
Thread-safe throttling to avoid redundant syscalls |
internal/icon |
Custom PNG generation for the 7-segment tray display |
Policies fire on aggregate capacity while discharging. Hysteresis prevents flicker: e.g. notify at 20%, reset only after capacity climbs to 23%. Suspend can delegate to logind at a lower threshold.
Footprint and deployment
- ~12 MB RSS in normal operation
- Fully static binary (
CGO_ENABLED=0) — no runtime dependencies - User systemd unit via
make install-service - Config at
~/.config/go-powerd/config.toml(TOML themes, policy thresholds)
What it is not
Not a generic power management framework. Not a dbus battery API wrapper. A focused tray utility for people who want the implementation to be inspectable and cheap to run.