NUT UPS Monitor
Costa Tsaousis (ktsaou) committed
Oct 9, 2014 at 01:59 UTC
5aff09af4fd7cdd042661bb5330c905af85c4779
1 file changed
+142
charts.d/nut.chart.sh
new
+142
@@ -0,0 +1,142 @@
1
+#!/bin/sh
2
+
3
+nut_ups=
4
+nut_update_every=2
5
+
6
+nut_check() {
7
+ if [ -z "${nut_ups}" ]
8
+ then
9
+ echo >&2 "nut: Please set nut_ups='ups_name' in $confd/nut.conf"
10
+ return 1
11
+ fi
12
+
13
+ upsc "${nut_ups}" >/dev/null
14
+ if [ ! $? -eq 0 ]
15
+ then
16
+ echo >&2 "nut: failed to fetch info for ups '$nut_ups'. Please set nut_ups='ups_name' in $confd/nut.conf"
17
+ return 1
18
+ fi
19
+
20
+ return 0
21
+}
22
+
23
+nut_create() {
24
+ # create the charts
25
+ cat <<EOF
26
+CHART nut.charge '' "UPS Charge" "percentage" nut '' area 21001 $nut_update_every
27
+DIMENSION battery_charge charge absolute 1 100
28
+
29
+CHART nut.battery_voltage '' "UPS Battery Voltage" "Volts" nut '' line 21002 $nut_update_every
30
+DIMENSION battery_voltage voltage absolute 1 100
31
+DIMENSION battery_voltage_high high absolute 1 100
32
+DIMENSION battery_voltage_low low absolute 1 100
33
+DIMENSION battery_voltage_nominal nominal absolute 1 100
34
+
35
+CHART nut.input_voltage '' "UPS Input Voltage" "Volts" nut '' line 21003 $nut_update_every
36
+DIMENSION input_voltage voltage absolute 1 100
37
+DIMENSION input_voltage_fault fault absolute 1 100
38
+DIMENSION input_voltage_nominal nominal absolute 1 100
39
+
40
+CHART nut.input_current '' "UPS Input Current" "Ampere" nut '' line 21004 $nut_update_every
41
+DIMENSION input_current_nominal nominal absolute 1 100
42
+
43
+CHART nut.input_frequency '' "UPS Input Frequency" "Hz" nut '' line 21005 $nut_update_every
44
+DIMENSION input_frequency frequency absolute 1 100
45
+DIMENSION input_frequency_nominal nominal absolute 1 100
46
+
47
+CHART nut.output_voltage '' "UPS Output Voltage" "Volts" nut '' line 21006 $nut_update_every
48
+DIMENSION output_voltage voltage absolute 1 100
49
+
50
+CHART nut.load '' "UPS Load" "percentage" nut '' area 21000 $nut_update_every
51
+DIMENSION load load absolute 1 100
52
+
53
+CHART nut.temp '' "UPS Temperature" "temperature" nut '' line 21007 $nut_update_every
54
+DIMENSION temp temp absolute 1 100
55
+EOF
56
+
57
+ return 0
58
+}
59
+
60
+
61
+nut_update() {
62
+ # the first argument to this function is the microseconds since last update
63
+ # pass this parameter to the BEGIN statement (see bellow).
64
+
65
+ # do all the work to collect / calculate the values
66
+ # for each dimension
67
+ # remember: KEEP IT SIMPLE AND SHORT
68
+
69
+ upsc "${nut_ups}" | awk "
70
+BEGIN {
71
+ battery_charge = 0;
72
+ battery_voltage = 0;
73
+ battery_voltage_high = 0;
74
+ battery_voltage_low = 0;
75
+ battery_voltage_nominal = 0;
76
+ input_voltage = 0;
77
+ input_voltage_fault = 0;
78
+ input_voltage_nominal = 0;
79
+ input_current_nominal = 0;
80
+ input_frequency = 0;
81
+ input_frequency_nominal = 0;
82
+ output_voltage = 0;
83
+ load = 0;
84
+ temp = 0;
85
+}
86
+/^battery.charge: .*/ { battery_charge = \$2 * 100 };
87
+/^battery.voltage: .*/ { battery_voltage = \$2 * 100 };
88
+/^battery.voltage.high: .*/ { battery_voltage_high = \$2 * 100 };
89
+/^battery.voltage.low: .*/ { battery_voltage_low = \$2 * 100 };
90
+/^battery.voltage.nominal: .*/ { battery_voltage_nominal = \$2 * 100 };
91
+/^input.voltage: .*/ { input_voltage = \$2 * 100 };
92
+/^input.voltage.fault: .*/ { input_voltage_fault = \$2 * 100 };
93
+/^input.voltage.nominal: .*/ { input_voltage_nominal = \$2 * 100 };
94
+/^input.current.nominal: .*/ { input_current_nominal = \$2 * 100 };
95
+/^input.frequency: .*/ { input_frequency = \$2 * 100 };
96
+/^input.frequency.nominal: .*/ { input_frequency_nominal = \$2 * 100 };
97
+/^output.voltage: .*/ { output_voltage = \$2 * 100 };
98
+/^ups.load: .*/ { load = \$2 * 100 };
99
+/^ups.temperature: .*/ { temp = \$2 * 100 };
100
+END {
101
+ print \"BEGIN nut.charge $1\";
102
+ print \"SET battery_charge = \" battery_charge;
103
+ print \"END\"
104
+
105
+ print \"BEGIN nut.battery_voltage $1\";
106
+ print \"SET battery_voltage = \" battery_voltage;
107
+ print \"SET battery_voltage_high = \" battery_voltage_high;
108
+ print \"SET battery_voltage_low = \" battery_voltage_low;
109
+ print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
110
+ print \"END\"
111
+
112
+ print \"BEGIN nut.input_voltage $1\";
113
+ print \"SET input_voltage = \" input_voltage;
114
+ print \"SET input_voltage_fault = \" input_voltage_fault;
115
+ print \"SET input_voltage_nominal = \" input_voltage_nominal;
116
+ print \"END\"
117
+
118
+ print \"BEGIN nut.input_current $1\";
119
+ print \"SET input_current_nominal = \" input_current_nominal;
120
+ print \"END\"
121
+
122
+ print \"BEGIN nut.input_frequency $1\";
123
+ print \"SET input_frequency = \" input_frequency;
124
+ print \"SET input_frequency_nominal = \" input_frequency_nominal;
125
+ print \"END\"
126
+
127
+ print \"BEGIN nut.output_voltage $1\";
128
+ print \"SET output_voltage = \" output_voltage;
129
+ print \"END\"
130
+
131
+ print \"BEGIN nut.load $1\";
132
+ print \"SET load = \" load;
133
+ print \"END\"
134
+
135
+ print \"BEGIN nut.temp $1\";
136
+ print \"SET temp = \" temp;
137
+ print \"END\"
138
+}
139
+"
140
+ return 0
141
+}
142
+