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 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
18 # the priority of nut related to other charts
24 run -t $nut_timeout upsc -l
28 run -t $nut_timeout upsc "$1"
34 # - 0 to enable the chart
35 # - 1 to disable the chart
39 require_cmd upsc || return 1
41 [ -z "$nut_ups" ] && nut_ups="$( nut_get_all )"
45 nut_get "$x" >/dev/null
48 nut_ids[$x]="$( fixid "$x" )"
51 error "cannot get information for NUT UPS '$x'."
54 if [ ${#nut_ids[@]} -eq 0 ]
56 error "Cannot find UPSes - please set nut_ups='ups_name' in $confd/nut.conf"
67 for x in "${nut_ids[@]}"
70 CHART nut_$x.charge '' "UPS Charge" "percentage" ups nut.charge area $((nut_priority + 1)) $nut_update_every
71 DIMENSION battery_charge charge absolute 1 100
73 CHART nut_$x.battery_voltage '' "UPS Battery Voltage" "Volts" ups nut.battery.voltage line $((nut_priority + 2)) $nut_update_every
74 DIMENSION battery_voltage voltage absolute 1 100
75 DIMENSION battery_voltage_high high absolute 1 100
76 DIMENSION battery_voltage_low low absolute 1 100
77 DIMENSION battery_voltage_nominal nominal absolute 1 100
79 CHART nut_$x.input_voltage '' "UPS Input Voltage" "Volts" input nut.input.voltage line $((nut_priority + 3)) $nut_update_every
80 DIMENSION input_voltage voltage absolute 1 100
81 DIMENSION input_voltage_fault fault absolute 1 100
82 DIMENSION input_voltage_nominal nominal absolute 1 100
84 CHART nut_$x.input_current '' "UPS Input Current" "Ampere" input nut.input.current line $((nut_priority + 4)) $nut_update_every
85 DIMENSION input_current_nominal nominal absolute 1 100
87 CHART nut_$x.input_frequency '' "UPS Input Frequency" "Hz" input nut.input.frequency line $((nut_priority + 5)) $nut_update_every
88 DIMENSION input_frequency frequency absolute 1 100
89 DIMENSION input_frequency_nominal nominal absolute 1 100
91 CHART nut_$x.output_voltage '' "UPS Output Voltage" "Volts" output nut.output.voltage line $((nut_priority + 6)) $nut_update_every
92 DIMENSION output_voltage voltage absolute 1 100
94 CHART nut_$x.load '' "UPS Load" "percentage" ups nut.load area $((nut_priority)) $nut_update_every
95 DIMENSION load load absolute 1 100
97 CHART nut_$x.temp '' "UPS Temperature" "temperature" ups nut.temperature line $((nut_priority + 7)) $nut_update_every
98 DIMENSION temp temp absolute 1 100
107 # the first argument to this function is the microseconds since last update
108 # pass this parameter to the BEGIN statement (see bellow).
110 # do all the work to collect / calculate the values
112 # remember: KEEP IT SIMPLE AND SHORT
115 for i in "${!nut_ids[@]}"
122 battery_voltage_high = 0;
123 battery_voltage_low = 0;
124 battery_voltage_nominal = 0;
126 input_voltage_fault = 0;
127 input_voltage_nominal = 0;
128 input_current_nominal = 0;
130 input_frequency_nominal = 0;
135 /^battery.charge: .*/ { battery_charge = \$2 * 100 };
136 /^battery.voltage: .*/ { battery_voltage = \$2 * 100 };
137 /^battery.voltage.high: .*/ { battery_voltage_high = \$2 * 100 };
138 /^battery.voltage.low: .*/ { battery_voltage_low = \$2 * 100 };
139 /^battery.voltage.nominal: .*/ { battery_voltage_nominal = \$2 * 100 };
140 /^input.voltage: .*/ { input_voltage = \$2 * 100 };
141 /^input.voltage.fault: .*/ { input_voltage_fault = \$2 * 100 };
142 /^input.voltage.nominal: .*/ { input_voltage_nominal = \$2 * 100 };
143 /^input.current.nominal: .*/ { input_current_nominal = \$2 * 100 };
144 /^input.frequency: .*/ { input_frequency = \$2 * 100 };
145 /^input.frequency.nominal: .*/ { input_frequency_nominal = \$2 * 100 };
146 /^output.voltage: .*/ { output_voltage = \$2 * 100 };
147 /^ups.load: .*/ { load = \$2 * 100 };
148 /^ups.temperature: .*/ { temp = \$2 * 100 };
150 print \"BEGIN nut_$x.charge $1\";
151 print \"SET battery_charge = \" battery_charge;
154 print \"BEGIN nut_$x.battery_voltage $1\";
155 print \"SET battery_voltage = \" battery_voltage;
156 print \"SET battery_voltage_high = \" battery_voltage_high;
157 print \"SET battery_voltage_low = \" battery_voltage_low;
158 print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
161 print \"BEGIN nut_$x.input_voltage $1\";
162 print \"SET input_voltage = \" input_voltage;
163 print \"SET input_voltage_fault = \" input_voltage_fault;
164 print \"SET input_voltage_nominal = \" input_voltage_nominal;
167 print \"BEGIN nut_$x.input_current $1\";
168 print \"SET input_current_nominal = \" input_current_nominal;
171 print \"BEGIN nut_$x.input_frequency $1\";
172 print \"SET input_frequency = \" input_frequency;
173 print \"SET input_frequency_nominal = \" input_frequency_nominal;
176 print \"BEGIN nut_$x.output_voltage $1\";
177 print \"SET output_voltage = \" output_voltage;
180 print \"BEGIN nut_$x.load $1\";
181 print \"SET load = \" load;
184 print \"BEGIN nut_$x.temp $1\";
185 print \"SET temp = \" temp;
188 [ $? -ne 0 ] && unset nut_ids[$i] && error "failed to get values for '$i', disabling it."
191 [ ${#nut_ids[@]} -eq 0 ] && error "no UPSes left active." && return 1