A zen-like Go toolkit for mindful battery monitoring, logging, and real-time visualization on Linux.
- Battery and power monitoring
- Configurable logging intervals
- Automatic log rotation
- Systemd integration
- Interactive TUI: real-time charts, predictions, zoom/pan, cycle count
- Screen-On Time (SOT) tracking - estimates daily usage patterns
- Suspend/shutdown detection - identifies system sleep periods and battery drain
- Weekly SOT visualization - bar charts showing daily usage trends
./install.sh- This will:
- Build the binary
- Install the binary to
~/.local/bin/ - Install, enable and start the systemd service, so
battery-zenstarts on boot and logs data in the background - Create default config file at
~/.config/battery-zen/config.toml
Note
Once installed through the script, you can run battery-zen commands directly from your terminal, with tab completions for bash and zsh shells. From next boot/suspend, the service will start logging data automatically in the background.
battery-zen tui # Launch TUI
battery-zen status # Show statusSee docs/TUI.md for advanced TUI features and controls.
make status # Service status
make logs # View logs
make stop # Stop service
make start # Start service
make uninstall # Remove everythingConfig files (TOML):
internal/config/config.toml(local)~/.config/battery-zen/config.toml(user)/etc/battery-zen/config.toml(system)
Key settings:
interval_secs: Data logging frequency (default: 60s)suspend_gap_minutes: Threshold for detecting suspend events (default: 5 min)max_window_zoom: Chart zoom limit in days (default: 10)- Chart colors, log rotation, and timezone settings
See config file for all available options.
CSV log: ~/.local/state/battery-zen/logs.csv
The TUI provides comprehensive battery analytics:
- Charge/Discharge Rates: Calculated using exponential weighted regression (recent data weighted higher)
- Time Estimates: Predicts time to full charge or empty based on current usage patterns
- SOT Calculation: Estimates screen-on time by analyzing gaps in data logging (≥5 minutes = suspend/shutdown, configurable)
- Current Session: Active time since last wake/boot
- Daily Trends: Bar chart showing SOT for the past 7 days
- Suspend Detection: Tracks sleep periods and battery drain during suspend
Note: SOT is calculated as a proxy based on continuous data logging. If the system is left idle with the screen off but Battery Zen still running, it will count toward SOT. The calculation assumes logging gaps ≥5 minutes indicate system suspend/shutdown.
See systemd/ for service files. Use make or copy manually for custom setups.
./uninstall.shgo build ./cmd/battery-zen
make cleanAll configuration options available in config files:
interval_secs = 60- Data logging frequency in secondsinterval_secs_on_ac = 60- Logging frequency when AC connectedtimezone = "Local"- Timezone for timestampslog_dir = "~/.local/state/battery-zen"- Directory for log fileslog_file = "logs.csv"- Name of the CSV log filemax_lines = 4000- Maximum lines in log before rotationtrim_buffer = 100- Lines to keep when trimming logmax_charge_percent = 100- Maximum charge threshold for predictionssuspend_gap_minutes = 5- Gap threshold for detecting suspend/shutdown events
day_color_number = -1- Terminal color for day data points (default foreground)night_color_number = 234- Terminal color for night data points (dark gray)day_start_hour = 7- Hour when day visualization starts (7 AM)day_end_hour = 19- Hour when night visualization starts (7 PM)max_window_zoom = 10- Maximum zoom window in days for charts