-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpwrstat
More file actions
executable file
·106 lines (86 loc) · 2.79 KB
/
Copy pathpwrstat
File metadata and controls
executable file
·106 lines (86 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
"""
pwrstat - Plugin to monitor CyberPower UPS via pwrstat
by Nelson Minar <nelson@monkey.org>, placed into the public domain
https://nelsonslog.wordpress.com/2012/01/26/cyberpower-pwrstatd-notes/
Updated by Justin Settle
Additional updates by Ken Link <klink@numberzero.org>
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 sensors
graph_vlabel value
graph_info Power Information from attached CyberPower UPS
graph_args '-l 0'
inV.label Utility Voltage
inV.info Line Voltage from Utility Provider
inV.min 0
inV.max 200
outV.label Output Voltage
outV.info Output Voltage from UPS
outV.min 0
outV.max 200
battery.label Battery Capacity (Percent)
battery.info Battery Charge in Percent
battery.min 0
battery.max 100
runtime.label Remaining Runtime (Minutes)
runtime.info Estimated Time Remaining on Battery Power
runtime.min 0
runtime.max 200
loadWatts.label Load (Watts)
loadWatts.info Current load in UPS in Watts
loadWatts.min 0
loadWatts.max 600
loadPct.label Load (Percent)
loadPct.info Current load on UPS in Percentage
loadPct.min 0
loadPct.max 100
loadPct.draw AREA
""")
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(b'\n')
data = {}
for datum in output[10:-2]:
name = datum[:29].strip(b'.').strip()
value = datum[31:].strip()
data[name] = value
print("inV.value", data[b"Utility Voltage"].split()[0].decode())
print("outV.value", data[b"Output Voltage"].split()[0].decode())
print("battery.value", data[b"Battery Capacity"].split()[0].decode())
print("runtime.value", data[b"Remaining Runtime"].split()[0].decode())
print("loadWatts.value", data[b"Load"].split()[0].decode())
print("loadPct.value", data[b"Load"].split()[1].split(b'(')[1].decode())
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
"""