Apcupsd add check for UPS online (#5037)
##### Summary fixes #3927 ##### Component Name external BASH collector module apcupsd. ##### Additional Information Add chart for online flag with 0/1. Only send that metric when the reported UPS stats are invalid.
Chris Akritidis committed
Dec 20, 2018 at 12:19 UTC
83e4b721fe11d3dfb938730e54a24c5edf385e6a
1 file changed
+56
-46
collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh
+56
-46
@@ -97,6 +97,9 @@ DIMENSION temp temp absolute 1 100
97
CHART apcupsd_${host}.time '' "UPS Time Remaining for ${host} on ${src}" "Minutes" ups apcupsd.time area $((apcupsd_priority + 2)) $apcupsd_update_every
98
DIMENSION time time absolute 1 100
99
100
+CHART apcupsd_${host}.online '' "UPS ONLINE flag for ${host} on ${src}" "boolean" ups apcupsd.online line $((apcupsd_priority + 8)) $apcupsd_update_every
101
+DIMENSION online online absolute 0 1
102
+
103
EOF
104
done
105
return 0
@@ -122,60 +125,67 @@ BEGIN {
125
input_voltage_min = 0;
126
input_voltage_max = 0;
127
input_frequency = 0;
125
- output_voltage = 0;
128
+ output_voltage = 0;
129
output_voltage_nominal = 0;
130
load = 0;
131
temp = 0;
132
time = 0;
133
}
131
-/^BCHARGE.*/ { battery_charge = \$3 * 100 };
132
-/^BATTV.*/ { battery_voltage = \$3 * 100 };
133
-/^NOMBATTV.*/ { battery_voltage_nominal = \$3 * 100 };
134
-/^LINEV.*/ { input_voltage = \$3 * 100 };
135
-/^MINLINEV.*/ { input_voltage_min = \$3 * 100 };
136
-/^MAXLINEV.*/ { input_voltage_max = \$3 * 100 };
137
-/^LINEFREQ.*/ { input_frequency = \$3 * 100 };
138
-/^OUTPUTV.*/ { output_voltage = \$3 * 100 };
139
-/^NOMOUTV.*/ { output_voltage_nominal = \$3 * 100 };
140
-/^LOADPCT.*/ { load = \$3 * 100 };
141
-/^ITEMP.*/ { temp = \$3 * 100 };
142
-/^TIMELEFT.*/ { time = \$3 * 100 };
134
+/^BCHARGE.*/ { battery_charge = \$3 * 100 };
135
+/^BATTV.*/ { battery_voltage = \$3 * 100 };
136
+/^NOMBATTV.*/ { battery_voltage_nominal = \$3 * 100 };
137
+/^LINEV.*/ { input_voltage = \$3 * 100 };
138
+/^MINLINEV.*/ { input_voltage_min = \$3 * 100 };
139
+/^MAXLINEV.*/ { input_voltage_max = \$3 * 100 };
140
+/^LINEFREQ.*/ { input_frequency = \$3 * 100 };
141
+/^OUTPUTV.*/ { output_voltage = \$3 * 100 };
142
+/^NOMOUTV.*/ { output_voltage_nominal = \$3 * 100 };
143
+/^LOADPCT.*/ { load = \$3 * 100 };
144
+/^ITEMP.*/ { temp = \$3 * 100 };
145
+/^TIMELEFT.*/ { time = \$3 * 100 };
146
+/^STATUS.*/ { online=(\$3 == \"ONLINE\")?1:0 };
147
END {
144
- print \"BEGIN apcupsd_${host}.charge $1\";
145
- print \"SET battery_charge = \" battery_charge;
146
- print \"END\"
147
-
148
- print \"BEGIN apcupsd_${host}.battery_voltage $1\";
149
- print \"SET battery_voltage = \" battery_voltage;
150
- print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
151
- print \"END\"
152
-
153
- print \"BEGIN apcupsd_${host}.input_voltage $1\";
154
- print \"SET input_voltage = \" input_voltage;
155
- print \"SET input_voltage_min = \" input_voltage_min;
156
- print \"SET input_voltage_max = \" input_voltage_max;
157
- print \"END\"
158
-
159
- print \"BEGIN apcupsd_${host}.input_frequency $1\";
160
- print \"SET input_frequency = \" input_frequency;
148
+ print \"BEGIN apcupsd_${host}.online $1\";
149
+ print \"SET online = \" online;
150
print \"END\"
151
163
- print \"BEGIN apcupsd_${host}.output_voltage $1\";
164
- print \"SET output_voltage = \" output_voltage;
165
- print \"SET output_voltage_nominal = \" output_voltage_nominal;
166
- print \"END\"
167
-
168
- print \"BEGIN apcupsd_${host}.load $1\";
169
- print \"SET load = \" load;
170
- print \"END\"
171
-
172
- print \"BEGIN apcupsd_${host}.temp $1\";
173
- print \"SET temp = \" temp;
174
- print \"END\"
175
-
176
- print \"BEGIN apcupsd_${host}.time $1\";
177
- print \"SET time = \" time;
178
- print \"END\"
152
+ if (online == 1) {
153
+ print \"BEGIN apcupsd_${host}.charge $1\";
154
+ print \"SET battery_charge = \" battery_charge;
155
+ print \"END\"
156
+
157
+ print \"BEGIN apcupsd_${host}.battery_voltage $1\";
158
+ print \"SET battery_voltage = \" battery_voltage;
159
+ print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
160
+ print \"END\"
161
+
162
+ print \"BEGIN apcupsd_${host}.input_voltage $1\";
163
+ print \"SET input_voltage = \" input_voltage;
164
+ print \"SET input_voltage_min = \" input_voltage_min;
165
+ print \"SET input_voltage_max = \" input_voltage_max;
166
+ print \"END\"
167
+
168
+ print \"BEGIN apcupsd_${host}.input_frequency $1\";
169
+ print \"SET input_frequency = \" input_frequency;
170
+ print \"END\"
171
+
172
+ print \"BEGIN apcupsd_${host}.output_voltage $1\";
173
+ print \"SET output_voltage = \" output_voltage;
174
+ print \"SET output_voltage_nominal = \" output_voltage_nominal;
175
+ print \"END\"
176
+
177
+ print \"BEGIN apcupsd_${host}.load $1\";
178
+ print \"SET load = \" load;
179
+ print \"END\"
180
+
181
+ print \"BEGIN apcupsd_${host}.temp $1\";
182
+ print \"SET temp = \" temp;
183
+ print \"END\"
184
+
185
+ print \"BEGIN apcupsd_${host}.time $1\";
186
+ print \"SET time = \" time;
187
+ print \"END\"
188
+ }
189
}"
190
# shellcheck disable=SC2181
191
if [ $? -ne 0 ]; then