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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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)
Method 2
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.
Method 3
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.
Method 4
sudo tlp-stat -b
It will show the current power consumption in milli Watt unit.
--- TLP 1.1 -------------------------------------------- +++ Battery Status /sys/class/power_supply/BAT1/manufacturer = SANYO /sys/class/power_supply/BAT1/model_name = L12S3F01 /sys/class/power_supply/BAT1/cycle_count = 16 /sys/class/power_supply/BAT1/energy_full_design = 32560 [mWh] /sys/class/power_supply/BAT1/energy_full = 16180 [mWh] /sys/class/power_supply/BAT1/energy_now = 16090 [mWh] /sys/class/power_supply/BAT1/power_now = 0 [mW] /sys/class/power_supply/BAT1/status = Unknown Charge = 99.4 [%] Capacity = 49.7 [%]
Method 5
For non-battery driven machines try cat /sys/class/hwmon/hwmonN/device/powerM_average – it shows the average power consumption in mW within the last /sys/class/hwmon/hwmonN/device/powerM_average_interval ms (usually 1s; N, M are integers) for each identified device. On modern dual-socket servers often N = {0..2}, one monitor for each CPU package and one for all PSUs together (check powerM_oem_info). You probably need to load the acpi_power_meter kernel module to get the related information.
Method 6
Last but not least for BMC driven *x machines one may try ipmitool dcmi power reading. On Linux it requires RW privileges for /dev/ipmi0 and the ipmi_si kernel module loaded, similar on Solaris 11.x /dev/bmc and module bmc. Other alternative is to use the LANplus variant of ipmitool if the BMC is accessible from remote.
The Instantaneous power reading: is usually ok, all other emitted values should be taken with some grains of salt ;-).
Example:
# ipmitool dcmi power reading
Instantaneous power reading: 138 Watts
Minimum during sampling period: 75 Watts
Maximum during sampling period: 420 Watts
Average power reading over sample period: 157 Watts
IPMI timestamp: Fri Jan 7 06:32:43 2022
Sampling period: 00000001 Seconds.
Power reading state is: activated
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0