Linux power consumption monitor

How to monitor power usage in Linux

Last updated on October 26, 2020 by Dan Nanni

It is important to measure power consumption in operating system especially when you try to maximize the battery life of your laptop, or reduce the energy bill of rack-mounted servers in a data center. Power usage monitor can also be helpful to diagnose issues with power management, or even buggy behaviors of applications.

In this post, I will describe how to monitor power usage in Linux operating system.

For Linux-based systems, you can use PowerTop , an ncurses -based command-line tool developed by Intel to monitor process-level power consumption, and to provide suggestions to optimize power management. PowerTop supports Intel, AMD, ARM, and UltraSparc processors while it is the most reliable on Intel processors for the obvious reason.

Install PowerTop on Linux

Install PowerTop on Ubuntu or Debian

Install PowerTop on CentOS, Fedora or RHEL

Run PowerTop

To launch PowerTop , simply run:

Once PowerTop is launched, you can press left/right arrow keys to navigate tab-based UI. PowerTop can start reporting power estimates after it has collected enough measurements, which can take a couple of minutes. Previous measurements are stored in /var/cache/powertop , and will be loaded upon subsequent PowerTop launch.

In Tunables menu, you can experiment with various power management settings in case some tunable parameters are not enabled on your Linux distribution.

For offline analysis, PowerTop allows you to export power monitoring results to csv or html format as follows.

To get more accurate estimates, you can run PowerTop in calibration mode as follows. The entire calibration process can take a couple of minutes. During calibration, PowerTop can disconnect your system from WiFi, adjust screen brightness, and generate USB device activities.

The screenshots of PowerTop are shown below.


How to Monitor and Optimize Power Usage on Linux?

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!


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:

Next, install the tool by executing the following command:

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:

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

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

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:

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

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:

Читайте также:  Краска для принтеров инксистем

Once it is installed, start the utility like this:

You will see the following output after running the command:

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

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:

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:

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:

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


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.


How to measure power consumption in watts using powerstat in Linux with examples

In my last article I had explained the various CPU c-states in detail and how you can disable the CPU states, and different commands which can show you the memory usage per process in Linux. These can help you troubleshoot performance related issues.
In this article I will show the usage of powerstat to measure power in watts for various tuned profile and also with some load.
I will be using Red Hat Enterprise Linux 7 (RHEL 7) for demonstrating the commands.

Install powerstat

If powerstat is available at your repository then you can install the same using

Or you can always download this tool based on your environment and install it locally.

IMPORTANT NOTE: The power usage will fluctuate mostly when a CPU/Memory/Disk IO eating process transitions from being idle to running multiple times. As based on the time taken for this transition i.e. coming from deeper CPU c-state to C) takes time and impacts the power usage. If a process is all the time in running state then the power usage will be constant.
With profile throughput-performance

Читайте также:  Linux create file echo

Case 1: System is Idle

Before starting let us measure the power usage when the system is completely idle
In the below example I am taking 60 samples or power usage taken per second.

So on my blade the average power usage when the system is idle is

As you see when the system is dile the CPU goes into deeper sleep state hence saving power.

Case 2: When the system is under load

To reproduce this environment I will use «stress» tool to put some load on my CPU, memory and disks.
I will be running below command in one of the terminal to put some load on the node

Next check the power usage

As you see the CPU are always at running state «C0» and the power usage is around

With profile latency-performance

In this tuned profile we set the force_latency value to «1» hence the CPU c-state will not go lower than C1 even when the system is idle. Hence the power usage will always be compartiviely high as the system never sleeps in real.

Case 1: System is Idle

Before starting let us measure the power usage when the system is completely idle

As expected the power usage when the system is idle here is

72W while for throughoput-performance the same was

Also if you notice the CPU c-state always stays at C1-HSW while for throughput-performance the active CPU c-state was C6-HSW when the system was idle.

Case 2: When the system is under load

To reproduce this environment I will use «stress» tool to put some load on my CPU, memory and disks.
I will be running below command in one of the terminal to put some load on the node

Next check the power usage

So here the results are almost same as with throughput-performance, since the CPU usage was always at C0 state.
Some more examples of using powerstat
NOTE: By default if powerstat is executed without any argument then it will collect 60 samples at 1 second intervals.

Enable all sampling collection

This will give collective output with «C-State Statistics», «Average CPU Frequency», «Thermal Zone Temperatures» and «Power Histogram»

Histogram (of 60 power measurements)

Histogram (of 60 CPU utilization measurements)

Range is zero, cannot produce histogram of CPU average frequencies

Enable Histogram

This will give you a history of CPU power usage summary at the end of execution

Histogram (of 60 power measurements)

Histogram (of 60 CPU utilization measurements)

Show process activity log

This will show process fork/exec/exit activity log at the end of execution

Log of fork()/exec()/exit() calls:

I hope the article was useful.

1 thought on “How to measure power consumption in watts using powerstat in Linux with examples”

I used Ubuntu Server 16.04 , so I tried powerstat -a, it show me device is not discharging, cannot measure power usage. could you tell me how to solve that ?


Поделиться с друзьями