Linux Commands

How to Monitor and Optimize Power Usage on Linux?

Battery use on Linux is particularly high as compared to other operating systems. One of the reasons behind this unusual power drainage is that the hardware vendors do not provide the essential documentation for Linux kernel developers to create the power optimized drivers. Linux holds just 2% of the market share in desktop technology which is why an adequate attention is not given in this area. As Linux users, we ought to be concerned about monitoring the power use on our systems and be aware of the different ways where we can optimize the battery/power usage.

Today, we will explore how to monitor the power usage on Linux using different ways. We will first see how it can be achieved via Graphical User Interface (GUI). Then, we’ll make use of the Linux command line to achieve the same. We will also discuss some methods to optimize the power usage on a Linux system. In this tutorial, we demonstrate the steps on an Ubuntu 22.04 system. The commands that are used in this guide are simple. And the tools that we use can be easily installed in Ubuntu 22.04. Most of the methods discussed here can be replicated on almost all Linux distributions.

Let’s get started!

Guide

The following are the steps that we will follow in the given order to understand how we can monitor the power usage as well as optimize it:

Monitor the Power Usage via GUI

Let’s begin by monitoring the power usage on Linux with the help of Gnome’s Power Statistics tool. This tool can be installed via the command line.

Install Gnome Power Statistics Tool

Here, we will see how we can install the Power Statistics tool using the Ubuntu’s command line by running a Linux command. Before installing the Power Statistics, update the system with this command:

sudo apt-get update

Next, install the tool by executing the following command:

sudo apt-get install gnome-power-manager

After this, the tool will be successfully installed and is ready to use.

View Power Statistics

Let’s now start using the tool. Go to the start menu. Type “Power Statistics” in the search bar and hit enter. Once you locate the application, tap to run it.

This is how the tool’s interface appears. You will see AC adapter details as shown in the following image:

To see the laptop battery’s power statistics, click on the “Laptop Battery” in the left panel.

Monitor the Power Usage through Ubuntu’s Command Line

In this section, we list a few ways to monitor the power usage using the Ubuntu’s command line.

Method 1: Upower Utility
To monitor the power usage using Upower utility, execute the following command:

upower -monitor-detail

Method 2: ACPI Utility
First of all, install the acpi if it is not installed in your system.

sudo apt-get install acpi

To monitor the power usage using acpi utility, issue the following command:

acpi -h

You can run the acpi command with the options that were mentioned previously to get the information on a particular resource.

Method 3: Batstat
First, we install the Batstat in our system and configure it. To do that, follow these commands:

git clone https://github.com/Juve45/batstat.git

cd batstat

sudo cp batstat /usr/local/bin/

sudo chmod +x /usr/local/bin/batstat

Now, run the batstat command to monitor the power usage statistics:

batstat

How to Use Less Power on a Linux System

In this section, we will discuss some of the ways in which we can optimize the power usage on a Linux system.

Method 1: Limiting the Screen Brightness
High brightness takes a good toll on your system’s power usage. If you adjust the brightness to the lowest level, you will feel the difference in the power that is utilized by your system. Brightness can be adjusted by tapping on the top-right of your screen where you can see the information like battery, wifi, and sound.

The following window opens where you can adjust the brightness:

Method 2: Limit the USB Devices
A plugged USB device derives power from your system’s power resources. To optimize your system’s power usage and battery life, keep your plugged usb devices to a minimum number.

Method 3: Enable TLP
TLP is an open source utility that is used for power optimization in a Linux system. To install TLP, run this command:

sudo apt-get install tlp

Once it is installed, start the utility like this:

sudo tlp start

You will see the following output after running the command:

To see the system and power statistics using TLP, issue the following command:

sudo tlp-stat -s

Method 4: Disable the Screensavers
You can also optimize the power usage by disabling the screen savers as they are heavy on the system.

Execute this command to disable the default screensaver:

xset s off

This setting is temporary as it disables the screensaver for the current login session only.

To permanently disable the screensaver, changes in the “.xsession” file have to be made. To make changes, open the file first with the nano editor like in the following:

sudo nano $HOME/.xsession

Now that the file is open, add the following line:

Once the line is added, save the file and reboot your system.

Method 5: Using Lightweight Software
You can make use of a power usage monitoring tool to keep a check on the software that are more resources hungry. Once you find out the heavy software on your system, you can get rid of them and shift to their alternatives that are lighter and don’t become a burden on the system’s power resources.

We can make use of the powertop utility to monitor the power usage statistics on our system. It can be installed using the following command:

sudo apt install powertop

To inspect the power usage statistics, run the following command:

sudo powertop

Conclusion

In today’s guide, we learned in detail on how we can monitor the system resource usage with the help of different tools. After exploring the different tools and utilities, we also dived into the solution on how to optimize the power usage on a Linux system using the various doable methods. The methods that we followed are very easy and create a great impact on the system’s performance and efficiency by carefully making use of the system’s resources and driving less power.

We hope you liked the tutorial.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.