grafana-battery
consists of a Python script that retrieves battery information from
Linux sysfs (/sys/class/power_supply/<BAT>/) and outputs it using
the InfluxDB Line Protocol, as well as a Grafana dashboard. The data
collected by invoking the script through Telegraf's exec input
plugin is stored in InfluxDB and can be visualized in Grafana.
Prerequisites
-
Linux (requires availability of
/sys/class/power_supply/) -
Python
-
InfluxDB v2
-
Telegraf
-
Grafana
Files
- battery-status.py
-
retrieves battery information and outputs it in the InfluxDB Line Protocol
- grafana-battery.json
-
Grafana dashboard
- telegraf-battery.conf
-
Example configuration for Telegraf
Install
Configuration of Telegraf
-
Place the Python script
Copy
battery-status.pyto a location where Telegraf can execute it, then give it execute permission.cp battery-monitor/battery-status.py /path/to/ chmod +x /path/to/battery-status.py -
Configure Telegraf
Add the following to
telegraf.conf(or an additional configuration file).[[inputs.exec]] commands = [ "/path/to/battery-status.py" ] data_format = "influx"If
outputs.influxdb_v2is not already configured, also add the following. Replace<INFLUXDB_TOKEN>,<ORG>, and<BUCKET>with appropriate values according to your environment.[[outputs.influxdb_v2]] # urls = ["http://127.0.0.1:8086"] token = "<INFLUXDB_TOKEN>" organization = "<ORG>" bucket = "<BUCKET>"
Installing the Grafana Dashboard
-
Grafana → Dashboards → Import
-
Upload the file or paste the JSON
-
Set the
bucketandmeasurement
Repository
License
-
GPL-3.0