25

Is there a way to return the current watt consumption on the command line? I have found about the powertop program, but have not seen a way to return the Watt consumption as a value to the command line. I'm thinking of some file that I can cat or grep.

21

On my system I can obtain the power drawn from the battery from

cat /sys/class/power_supply/BAT0/power_now
9616000

On Thinkpads if the tp_smapi module is loaded, the file is

cat /sys/devices/platform/smapi/BAT0/power_now

The value seems to be in µW, though. You can convert it with any tool you're comfortable with, e.g. awk:

awk '{print $1*10^-6 " W"}' /sys/class/power_supply/BAT0/power_now
9.616 W

In case you cannot find the location within the sysfs file system, you can search for it:

find /sys -type f -name power_now 2>/dev/null

Additionally, the package lm-sensors may be used to determine the system power usage on some machines:

# sensors power_meter-acpi-0
power_meter-acpi-0
Adapter: ACPI interface
power1:      339.00 W  (interval =   1.00 s)
6

On a laptop by reading the ACPI data from either procfs or sysfs. On my system the files are:

/proc/acpi/battery/BAT0/state
/sys/bus/acpi/drivers/battery/PNP0C0A:00/power_supply/BAT0/power_now

Note that the sysfs is heavily symlinked so there are many ways to reach the file. power_now is the file name you are looking for.

6

My laptop has none of these (it also has no battery currently), but it does have a "powercap" device.
It seems this device is able to set restrictions on the user power.

And it (naturally) can read the power draw in order to enforce them.
The power draw can be found at the energy_uj file, i.e.:

cat /sys/class/powercap/*/energy_uj

It'll show the lecture (or lectures, if you have many powercap devices) in micro-Joules. This is actually a counter of the energy consumed, so you need to divide it by a time delta in order to get the power.

Is this the power drawn by my laptop, or just a part of it? I don't know.

  • Well, these devices are fairly common on new computers... On all of my tests, at least one of them shows a realistic power draw value with very good precision. I should test with a multimeter, though. – Alba Mendez Oct 12 '14 at 9:03
  • This seems a pretty nice solution. Where do you get the time delta from? – Freefri Jan 11 '17 at 13:01
  • @Freefri you read the value, wait 1 second, read the value again. 1 second is your delta. (Energy_now-Energy_one_second_ago) / 1 second = joules consumed per second (or watts, 1 watt = 1 joule / 1 second) – GDR Nov 10 '17 at 22:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.