1 # no need for shebang - this file is loaded from charts.d.plugin
4 # real-time performance and health monitoring, done right!
5 # (C) 2016-2017 Costa Tsaousis <costa@tsaousis.gr>
9 # a space separated list of UPS names
10 # if empty, the list returned by 'upsc -l' will be used
13 # how frequently to collect UPS data
16 # how much time in seconds, to wait for nut to respond
19 # set this to 1, to enable another chart showing the number
20 # of UPS clients connected to upsd
23 # the priority of nut related to other charts
29 run -t $nut_timeout upsc -l
33 run -t $nut_timeout upsc "$1"
35 if [ "${nut_clients_chart}" -eq "1" ]
37 printf "ups.connected_clients: "
38 run -t $nut_timeout upsc -c "$1" | wc -l
45 # - 0 to enable the chart
46 # - 1 to disable the chart
50 require_cmd upsc || return 1
52 [ -z "$nut_ups" ] && nut_ups="$( nut_get_all )"
56 nut_get "$x" >/dev/null
59 nut_ids[$x]="$( fixid "$x" )"
62 error "cannot get information for NUT UPS '$x'."
65 if [ ${#nut_ids[@]} -eq 0 ]
67 error "Cannot find UPSes - please set nut_ups='ups_name' in $confd/nut.conf"
78 for x in "${nut_ids[@]}"
81 CHART nut_$x.charge '' "UPS Charge" "percentage" ups nut.charge area $((nut_priority + 1)) $nut_update_every
82 DIMENSION battery_charge charge absolute 1 100
84 CHART nut_$x.battery_voltage '' "UPS Battery Voltage" "Volts" ups nut.battery.voltage line $((nut_priority + 2)) $nut_update_every
85 DIMENSION battery_voltage voltage absolute 1 100
86 DIMENSION battery_voltage_high high absolute 1 100
87 DIMENSION battery_voltage_low low absolute 1 100
88 DIMENSION battery_voltage_nominal nominal absolute 1 100
90 CHART nut_$x.input_voltage '' "UPS Input Voltage" "Volts" input nut.input.voltage line $((nut_priority + 3)) $nut_update_every
91 DIMENSION input_voltage voltage absolute 1 100
92 DIMENSION input_voltage_fault fault absolute 1 100
93 DIMENSION input_voltage_nominal nominal absolute 1 100
95 CHART nut_$x.input_current '' "UPS Input Current" "Ampere" input nut.input.current line $((nut_priority + 4)) $nut_update_every
96 DIMENSION input_current_nominal nominal absolute 1 100
98 CHART nut_$x.input_frequency '' "UPS Input Frequency" "Hz" input nut.input.frequency line $((nut_priority + 5)) $nut_update_every
99 DIMENSION input_frequency frequency absolute 1 100
100 DIMENSION input_frequency_nominal nominal absolute 1 100
102 CHART nut_$x.output_voltage '' "UPS Output Voltage" "Volts" output nut.output.voltage line $((nut_priority + 6)) $nut_update_every
103 DIMENSION output_voltage voltage absolute 1 100
105 CHART nut_$x.load '' "UPS Load" "percentage" ups nut.load area $((nut_priority)) $nut_update_every
106 DIMENSION load load absolute 1 100
108 CHART nut_$x.temp '' "UPS Temperature" "temperature" ups nut.temperature line $((nut_priority + 7)) $nut_update_every
109 DIMENSION temp temp absolute 1 100
112 if [ "${nut_clients_chart}" = "1" ]
115 CHART nut_$x.clients '' "UPS Connected Clients" "clients" ups nut.clients area $((nut_priority + 8)) $nut_update_every
116 DIMENSION clients '' absolute 1 1
127 # the first argument to this function is the microseconds since last update
128 # pass this parameter to the BEGIN statement (see bellow).
130 # do all the work to collect / calculate the values
132 # remember: KEEP IT SIMPLE AND SHORT
135 for i in "${!nut_ids[@]}"
142 battery_voltage_high = 0;
143 battery_voltage_low = 0;
144 battery_voltage_nominal = 0;
146 input_voltage_fault = 0;
147 input_voltage_nominal = 0;
148 input_current_nominal = 0;
150 input_frequency_nominal = 0;
155 do_clients = ${nut_clients_chart};
157 /^battery.charge: .*/ { battery_charge = \$2 * 100 };
158 /^battery.voltage: .*/ { battery_voltage = \$2 * 100 };
159 /^battery.voltage.high: .*/ { battery_voltage_high = \$2 * 100 };
160 /^battery.voltage.low: .*/ { battery_voltage_low = \$2 * 100 };
161 /^battery.voltage.nominal: .*/ { battery_voltage_nominal = \$2 * 100 };
162 /^input.voltage: .*/ { input_voltage = \$2 * 100 };
163 /^input.voltage.fault: .*/ { input_voltage_fault = \$2 * 100 };
164 /^input.voltage.nominal: .*/ { input_voltage_nominal = \$2 * 100 };
165 /^input.current.nominal: .*/ { input_current_nominal = \$2 * 100 };
166 /^input.frequency: .*/ { input_frequency = \$2 * 100 };
167 /^input.frequency.nominal: .*/ { input_frequency_nominal = \$2 * 100 };
168 /^output.voltage: .*/ { output_voltage = \$2 * 100 };
169 /^ups.load: .*/ { load = \$2 * 100 };
170 /^ups.temperature: .*/ { temp = \$2 * 100 };
171 /^ups.connected_clients: .*/ { clients = \$2 };
173 print \"BEGIN nut_$x.charge $1\";
174 print \"SET battery_charge = \" battery_charge;
177 print \"BEGIN nut_$x.battery_voltage $1\";
178 print \"SET battery_voltage = \" battery_voltage;
179 print \"SET battery_voltage_high = \" battery_voltage_high;
180 print \"SET battery_voltage_low = \" battery_voltage_low;
181 print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
184 print \"BEGIN nut_$x.input_voltage $1\";
185 print \"SET input_voltage = \" input_voltage;
186 print \"SET input_voltage_fault = \" input_voltage_fault;
187 print \"SET input_voltage_nominal = \" input_voltage_nominal;
190 print \"BEGIN nut_$x.input_current $1\";
191 print \"SET input_current_nominal = \" input_current_nominal;
194 print \"BEGIN nut_$x.input_frequency $1\";
195 print \"SET input_frequency = \" input_frequency;
196 print \"SET input_frequency_nominal = \" input_frequency_nominal;
199 print \"BEGIN nut_$x.output_voltage $1\";
200 print \"SET output_voltage = \" output_voltage;
203 print \"BEGIN nut_$x.load $1\";
204 print \"SET load = \" load;
207 print \"BEGIN nut_$x.temp $1\";
208 print \"SET temp = \" temp;
212 print \"BEGIN nut_$x.clients $1\";
213 print \"SET clients = \" clients;
217 [ $? -ne 0 ] && unset nut_ids[$i] && error "failed to get values for '$i', disabling it."
220 [ ${#nut_ids[@]} -eq 0 ] && error "no UPSes left active." && return 1