Cyberpower pwrstatd notes

I bought a Cyberpower UPS for my Linux server. I mostly like it, but the Linux software they include for it (pwrstat and pwrstatd) is comically bad. Network UPS Tools supports this UPS hardware too, if I weren’t so invested in this software already I’d try it instead.

Here are some bugs:

  1. There’s no source code available, just two little ELF binaries pwrstat and pwrstatd
  2. pwrstatd has to run as root, not a big surprise since it can shutdown the machine, but see bug #1. Also pwrstat (the userspace program) has to run as root, even to get the UPS status! It seems to mmap() itself into pwrstatd :-(
  3. The default configuration is to shut down your machine after 60 seconds of power failure, then shut the whole UPS off after 10 minutes. That’s awfully aggressive.
  4. Once a Linux box is shutdown, the ACPI system means it won’t reboot itself again when power is restored. Wake-on-LAN is the right way to fix this, I don’t know a quick and dirty way.
  5. The various utility shell scripts /etc/pwrstatd-*.sh are very poorly written. The mail program assumes /bin/mail has a -r flag (mine doesn’t). One script has a test for ENABLE_EMAIL being “YES”, the other tests for it being “yes”. None of the test arguments are quoted so missing variables throw shell syntax errors.
  6. Did I mention all the real work is done in pwrstatd, which runs as root, and for which there is no source code provided?

The cool thing about the UPS is the status report it gives over the USB includes a bunch of data, including how many watts the UPS is driving right now. I wrote a little Munin script and now I have a fancy graph of my server’s power consumption.

That graph above includes me unplugging the UPS and letting it run to zero. Original estimate was 82 minutes of runtime, actually got about 70. Oddly the power drain went up 10W after unplugged; the inefficiency of the AC generation?

This UPS seems to consume 10W of its own even when fully charged, and about 20W when charging. Not happy about that 10W. Also the “battery capacity” value is totally bogus during charging; it only updates when I force the UPS to run off battery or run a self-test.

Here’s my Munin plugin (first ever!)


#!/usr/bin/env python

"""
pwrstat - Plugin to monitor Cyberpower UPS via pwrstat

by Nelson Minar <nelson@monkey.org>, placed into the public domain

Unfortunately this plugin must run as root, because pwrstat requires
root to even read data from the UPS.
"""

import sys, subprocess

# config
if len(sys.argv) > 1:
 if sys.argv[1] == "config":
 print """
graph_title Cyberpower UPS Status
graph_category UPS
graph_vlabel value

inV.label Utility Voltage
inV.min 0
inV.max 200
inV.warning 100:130

outV.label Output Voltage
outV.min 0
outV.max 200
outV.warning 100:130

battery.label Battery Capacity (Percent)
battery.min 0
battery.max 100
battery.warning 35:105

runtime.label Remaining Runtime (Minutes)
runtime.min 0
runtime.max 200
runtime.warning 10:200

loadWatts.label Load (Watts)
loadWatts.min 0
loadWatts.max 1000
loadWatts.warning 30:150

loadPct.label Load (Percent)
loadPct.min 0
loadPct.max 100
loadPct.warning 0:75
"""
 sys.exit(0)
 else:
 sys.stderr.write("Unknown argument %s\n" % sys.argv[1])
 sys.exit(0)

# fetch

output = subprocess.check_output(("/usr/sbin/pwrstat", "-status"), shell=False)
output = output.split('\n')
data = {}
for datum in output[10:-2]:
 name = datum[:29].strip('.').strip()
 value = datum[31:].strip()
 data[name] = value

print "inV.value", data["Utility Voltage"].split()[0]
print "outV.value", data["Output Voltage"].split()[0]
print "battery.value", data["Battery Capacity"].split()[0]
print "runtime.value", data["Remaining Runtime"].split()[0]
print "loadWatts.value", data["Load"].split()[0]
print "loadPct.value", data["Load"].split()[1].split('(')[1]

sys.exit(0)

# This is the pwrstat format that we parse. Note, it contains tabs.
# Comes from pwrstat version 1.2
exampleOutput="""
The UPS information shows as following:

Properties:
 Model Name................... UPS CP1000AVRLCD
 Firmware Number.............. BFC7101.4K1
 Rating Voltage............... 120 V
 Rating Power................. 600 Watt

Current UPS status:
 State........................ Normal
 Power Supply by.............. Utility Power
 Utility Voltage.............. 125 V
 Output Voltage............... 124 V
 Battery Capacity............. 100 %
 Remaining Runtime............ 77 min.
 Load......................... 54 Watt(9 %)
 Line Interaction............. None
 Test Result.................. Passed at 2012/01/25 01:39:47
 Last Power Event............. None
"""

4 thoughts on “Cyberpower pwrstatd notes

  1. For #3, most BIOSes have an option for what to do when power is restored. The options are usually: always on, last state, always off. Seems like you want always on which is never? the default.

  2. Hi, found this post via google when I was looking to see if anyone else had run into my issue with pwrstatd.

    I don’t know if its worth reporting to Cyberpower, but it seems to have an issue on Fedora 16 with 3.2.3-2 kernel. The daemon just shuts down the computer as soon as it starts. Not sure why it does that, and I don’t really care.

  3. Huh, weird. You can configure it to never shut down the computer via the shell scripts, but that’s just hiding problems.

  4. Yeah, exactly. I just disabled pwrstatd completly. It was just a case of “oh wow they have linux support” I wonder how well it works. It was usefult to diagnose power fluctuations and spikes we had at the old office, but not really needed for a single desktop solution. The ups was really just purchased as a power conditioner and to protect us from the momentary power fluctions we were expereincing.

Comments are closed.