はっくはっくキッチン
Hack Hack Kitchen

Script and Grafana-dashboard to monitor battery status on Linux

 2026/02/10

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.

Screenshot of grafana-battery
Screenshot of grafana-battery

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

  1. Place the Python script

    Copy battery-status.py to 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
  2. 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_v2 is 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

  1. Grafana → Dashboards → Import

  2. Upload the file or paste the JSON

  3. Set the bucket and measurement

License

  • GPL-3.0