25 October 2014

Wattage on a GNU/Linux box

Ever wanted to know how much power your GNU/Linux box uses? We'll here's a one-liner for showing the number of Watts that it draws:

echo "3k * 1000000000000 / p" | cat /sys/class/power_supply/BAT1/voltage_now /sys/class/power_supply/BAT1/current_now - | dc

All you need to get the above to work, is dc. Linux's sysfs also changes from time to time, so it could be that these 2 files in /sys/ get moved or renamed from time to time.
ps. My laptop, running a 3.16-2 kernel, is drawing 8.975 Watts as I'm writing this ;)