Tools for checking ACPI battery data

Fully Charged

Article from Issue 202/2017

Linux offers some useful command-line tools that leverage the ACPI power management framework to display detailed data on the status of a laptop battery.

The quality of life for any laptop owner depends on the battery maintaining enough charge to operate off the power grid. Eventually, however, you will see a message informing you that the charge has reached a minimum threshold, and you have to save your data quickly or else switch to mains mode to continue working while the battery charges in the background.

The data for the warning message come from the Advanced Configuration and Power Interface (ACPI) [1] [2]. ACPI, which first appeared in 1996, has now replaced its predecessor, Advanced Power Management (APM); the current version 6 dates from April 2015. (For more information on APM and ACPI check out TuxMobil [3] and the ACPI how-to [4].)

ACPI used to be a separate component in Linux, but the Linux kernel developers now maintain ACPI functionality within the framework of the Unified Extensible Firmware Interface (UEFI) [5]. Linux comes with some command-line tools that let you read information on battery status and health. For Debian and its derivatives, you'll need the acpi, acpid, and acpi-support-base packages.

Up to Linux 2.6.26, ACPI information was found on the proc filesystem [6] below /proc/acpi/ [7]. The developers have now reorganized the filesystem and have moved the information to /sys/class/power_supply/.

Checking on Power

Figure 1 shows power data for a Lenovo ThinkPad X 250 running Debian 8. The device has two batteries, one built-in and one replaceable, so the first command in Figure 1 reveals three power supplies: AC power, as well as the first and second batteries (BAT0 and BAT1).

Figure 1: Using the sysfs pseudo filesystem, you can determine the available power supplies and discover detailed information on the power components.

The following command in Figure 1:

cat /sys/class/power_supply/BAT0/status

outputs the contents of the .../BAT0/status file, which shows the status of BAT0. In this case, the command reveals that BAT0 is charging. The other possible messages are Discharging and Fully charged.

You can always obtain some basic information by parsing individual files in the /sys/class/power_supply/ directory. But finding and interpreting the data can cause some effort. A number of utilities make life easier and serve up the data in a human-readable format. These utilities include Upower [8], Acpi [9], and Acpitool [10], as well as the Intelligent Battery Monitor, Ibam [11].

All four programs provide information on the various power sources. Upower uses the --enumerate switch (short form: -e) (Listing 1); Acpi has two options: --ac-adapter (-a) and --battery (-b) (Listing 2).

Listing 1

Upower with enumerate


Listing 2

Acpi Power Info


Acpitool provides a compact overview (Listing 3). Whereas Upower only lists the individual energy sources, Acpi and Acpitool provide more details.

Listing 3

Overview in Acpitool


If the output in the terminal does not appeal to you, most Linux desktop systems provide a tool for monitoring power usage (Figure 2).

Figure 2: Checking the battery state in Mate's Power Statistics tool.


If you call Upower with the --show-info (-i) option and the name of the power source, it displays all the matching details. The --dump (-d) switch lists the details for all the power sources.

Listing 4 shows the results for the second battery in the device. In addition to the manufacturer, the model, the serial number, and the type – a lithium-ion battery in this case – Upower lists more specifications that are useful for everyday operations. Among other things, it shows the battery's charge capacity (only around 90 percent here). Designed for a capacity of 71Wh, the battery now only manages 64Wh due to its advanced age. The time to full line shows that it will take around 90 minutes to fully charge the battery.

Listing 4

Details in Upower


The acpi command provides less detail but at least enough information for a quick overview. Call acpi with the --details option (-i) enabled. The command in Listing 5 uses grep to limit the output to the information for the first battery (Battery 0).

Listing 5

Quick Overview in Acpi


For a complete overview of all power sources, call acpi --everything (short form -V) or acpitool -Be. In addition to the charge status of the batteries, the output includes the value of the temperature sensor, as well as information about the cooling system (Figure 3). You can retrieve the necessary information using the options --thermal (short form -t) or --cooling (short form -c).

Figure 3: In addition to the information about power sources, Acpi provides data on the temperature sensor and cooling system.

The --show-empty (-s) option tells acpi to show you devices that are not currently working. You can thus identify defective or improperly connected system components. The output in Listing 6 indicates that something is wrong with two batteries.

Listing 6

Diagnosing Battery Problems


Lifetime and Charging Duration

The Ibam tool calculates both the remaining lifetime and the probable charging time. Listing 7 shows a program call with the --battery option, which returns a remaining battery life of 19 minutes and forecasts a charging time of around 90 minutes.

Listing 7

Ibam: Checking Battery Time


For graphical output, combine Ibam with Gnuplot [12]. Ibam always stores the time values for the charge state locally below ~/.ibam/. The --plot option evaluates this data. You will see a Gnuplot window displaying the charge state (Figure 4), where the x axis represents the recorded charge state and the y axis shows the time.

Figure 4: The Ibam tool stores the values from each call, letting you output the data as a chart.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95