lhl / batterylog

Linux laptop battery logging tool
GNU General Public License v3.0
26 stars 5 forks source link

batterylog

Linux laptop battery logging tool

A simple Python app with few dependencies that reads your sysfs-class-power numbers and records them to a local sqlite3 db with an "event" tag.

It was built to track suspend power usage for Framework laptops, but is flexible/easily extensible to do all kinds of other stuff.

Running

Makes sure you meet the requirements, clone the repo, and run INSTALL.sh - this will move the cloned repo to /opt/batterylog and install the script that logs into a sqlite3 DB at /opt/batterylog/batterylog.db.

You can run /opt/batterylog/batterylog without any parameters and it will calculate the power usage from the last suspend/resume cycle:

$ /opt/batterylog/batterylog
Slept for 8.72 hours
Used 6.10 Wh, an average rate of 0.70 W
For your 53.67 Wh battery this is 1.30%/hr or 31.29%/day

This script should work w/ any laptop that has a battery available via sysfs (it looks for the first battery located by /sys/class/power_supply/BAT*). This script has currently only been tested with a Framework laptop and the script doesn't check that all values exist (some batteries don't report some values). It's small enough though that it should be easy to debug/modify for your own purposes. Also, while it stores and keeps all historical values in sqlite, it doesn't really do much else, like have a UI for exposing previous sleeps, etc yet.

The expectation for this release is that the user would be comfortable writing some of their own queries or scripts if they want to do more.

Requirements

Packaging

Other Related Tools

Other Related Python Libraries

Reference