34

This question already has an answer here:

I've been asked to estimate the power consumption of the servers I run for my laboratory. I thought that I'd ask if there was some handy Linux commandline to get the power consumption of the server. It looks like powertop is useful for minimizing power consumption but it does not seem to show information that server A is using B watts.

Is there something buried in the /proc system that would help me out?

marked as duplicate by Anthon, Zelda, rahmu, slm, manatwork Jan 21 '14 at 13:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Do you mean powertop shows no ACPI power usage estimate available? – Mikel Apr 1 '11 at 3:00
  • It may be worth mentioning that there are instruments available for measuring current/voltage. A current clamp around a power cord can measure current, then multiplied by the mains voltage (120V?). For an estimate, you could even turn the system on and see how much the power meter speeds up. – mbowden May 10 '18 at 14:07
15

If your computer actually keeps track of power (e.g. notebook), than on kernel 3.8.11 you can use the command below. It returns power measured in microwatts.

cat /sys/class/power_supply/BAT0/power_now

This works on kernel 3.8.11 (Ubuntu Quantal mainline generic).

  • 3
    It actual is in µW and can be printed like this in terms of watts: awk '{print $1*10^-6 " W"}' /sys/class/power_supply/BAT0/power_now – Matt Jul 27 '16 at 0:34
  • @Matt Yes, you are right. Answer corrected. Thank you. – Adam Ryczkowski Jul 27 '16 at 15:02
  • If your system does not have the file power_now in /sys/class/power_supply/BAT0/, you can multiply the values in the files current_now and voltage_now from that directory to get power_now (don't forget to convert units accordingly, both files use µ units). – Tomáš Peitl May 12 '18 at 17:50
10

Computers generally don't track the current they are drawing. It is common that there are voltage sensors that are readable.

Power consumption can vary widely over time depending on workload. CPUs now throttle back when load is low. Disks will shutdown when idle. Tools like powertop will track processes which trigger increases in power consumption. Other tools will aggressively tune down power consumption.

UPSs care about power consumption and often have accessible data.

The manufacturers specs will give you some idea of power consumption, but reconfiguration of hardware can change power consumption. This is probably a good place to start and estimate. Adding new devices or replacing existing ones may alter the power load.

There are devices like Kill-A-Watt that can be used to measure power consumption. However, they require disconnecting the device so that the power runs through the device.

You may want to invest in or borrow a current meter which works by clipping around the wire. This would allow you to calculate volt-amps. This is typically different (higher) than the wattage for servers.

  • It's also worth noting that UPSes care both about peak as well as sustained power draw. Peak load will happen during the initial phase of power-on when everything (particularly everything mechanical like fans and spinning platter drives) starts up, and whenever the system is working really hard for some reason. Sustained and average load will almost certainly be lower for many of the reasons you mention in your answer. – a CVn Jun 6 '13 at 11:57
  • Startup load can be significantly above the running load. On a previous project we would blow the fuses in the breaker box during startup from a full shutdown. During normal usage our load was about 30% of the fuse rating. – BillThor Jun 7 '13 at 0:23
9

Another KISS solution completing Adam's sugestion. This is for people who dont have a power_now file. (Arch)

echo - | awk "{printf \"%.1f\", \
$(( \
  $(cat /sys/class/power_supply/BAT1/current_now) * \
  $(cat /sys/class/power_supply/BAT1/voltage_now) \
)) / 1000000000000 }" ; echo " W "

Reports the actual power draw in Watts with one decimal place.

  • only works if it has a battery. – KFL Aug 27 '18 at 7:07
  • When plugged in reports 0.0 W when unplugged reports 44.3 W. Works for me. – WinEunuuchs2Unix Oct 25 '18 at 23:11
  • If you get syntax error: operand expected (error token is "* "), then it's possible the path in the cat command is non-existent. For me on Ubuntu 16.04, changing the 2 instance of BAT1 to BAT* fixed that. – Garrett Nov 12 '18 at 21:54
4

I don't think most servers introspect their power consumption, at least not in a form that Linux can access. You might have better luck querying the servers' LOM modules (if any), but I usually get this kind of information from remote power strips.

4

freedektop's upower does the trick over dbus. My laptop need between 8 and 12 watts. Nice.

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