Skip to content

Check sensors-battery

Overview

Reports battery status information including charge percentage, time remaining, and power source (AC or battery). Alerts when the charge left drops to --warning or --critical; a battery that is plugged in, a host without one, and a host whose metrics cannot be determined stay OK.

Important Notes:

  • Run sensors-detect --auto beforehand to scan the system for hardware monitoring chips supported by libsensors / lm_sensors

Data Collection:

  • Uses psutil.sensors_battery() to read battery charge percentage, time remaining, and power plug status

Fact Sheet

Fact Value
Check Plugin Download https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/sensors-battery
Nagios/Icinga Check Name check_sensors_battery
Check Interval Recommendation Every minute
Can be called without parameters Yes
Runs on Cross-platform
Compiled for Windows No (runs with Python interpreter)
3rd Party Python modules psutil

Help

usage: sensors-battery [-h] [-V] [--always-ok] [-c CRIT] [--no-perfdata]
                       [-w WARN]

Reports battery status information including charge percentage, time
remaining, and power source (AC or battery). Alerts when the charge left drops
to `--warning` or `--critical`; a battery that is plugged in, a host without
one, and a host whose metrics cannot be determined stay OK.

options:
  -h, --help           show this help message and exit
  -V, --version        show program's version number and exit
  --always-ok          Always returns OK.
  -c, --critical CRIT  CRIT threshold for battery power left, in percent.
                       Default: 5
  --no-perfdata        Suppress the performance data section from the output.
                       The status message and the exit code are unaffected, so
                       alerting keeps working while trending data is dropped.
  -w, --warning WARN   WARN threshold for battery power left, in percent.
                       Default: 20

Documentation:
https://linuxfabrik.github.io/monitoring-plugins/check-plugins/sensors-battery/

Usage Examples

./sensors-battery --warning=20 --critical=5

Output:

94.13%, 4h 40m left (not plugged in and discharging)

States

  • OK if battery power is above the warning threshold or if the battery is plugged in.
  • OK if no battery is installed.
  • WARN if battery power left is at or below --warning (default: 20%).
  • CRIT if battery power left is at or below --critical (default: 5%).
  • UNKNOWN if the platform is not supported by psutil.
  • --always-ok suppresses all alerts and always returns OK.

Perfdata / Metrics

Name Type Description
battery_percent Percentage Battery charge level.
battery_secsleft Seconds Estimated time remaining on battery.

Troubleshooting

Python module "psutil" is not installed.

Install psutil: pip install psutil or dnf install python3-psutil.

Credits, License