@cryptotaxi247 / netdata-1 / commits / 5fb763505

Add a apcupsd status code metric (#16361)

Co-authored-by: ilyam8 <ilya@netdata.cloud>

thomasbeaudry committed Nov 13, 2023 at 08:51 UTC 5fb7635057cdeea3a1debfaaf1a63716e03e8af6
3 files changed +257 -79
collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh
+139 -79
@@ -50,7 +50,7 @@ apcupsd_check() {
50
51 local host working=0 failed=0
52 for host in "${!apcupsd_sources[@]}"; do
53 - apcupsd_get "${apcupsd_sources[${host}]}" > /dev/null
53 + apcupsd_get "${apcupsd_sources[${host}]}" >/dev/null
54 # shellcheck disable=2181
55 if [ $? -ne 0 ]; then
56 error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}."
@@ -77,7 +77,7 @@ apcupsd_create() {
77 local host
78 for host in "${!apcupsd_sources[@]}"; do
79 # create the charts
80 - cat << EOF
80 + cat <<EOF
81 CHART apcupsd_${host}.charge '' "UPS Charge" "percentage" ups apcupsd.charge area $((apcupsd_priority + 2)) $apcupsd_update_every '' '' 'apcupsd'
82 DIMENSION battery_charge charge absolute 1 100
83
@@ -110,13 +110,28 @@ CHART apcupsd_${host}.time '' "UPS Time Remaining" "Minutes" ups apcupsd.time ar
110 DIMENSION time time absolute 1 100
111
112 CHART apcupsd_${host}.online '' "UPS ONLINE flag" "boolean" ups apcupsd.online line $((apcupsd_priority + 9)) $apcupsd_update_every '' '' 'apcupsd'
113 -DIMENSION online online absolute 0 1
113 +DIMENSION online online absolute 1 1
114
115 CHART apcupsd_${host}.selftest '' "UPS Self-Test status" "status" ups apcupsd.selftest line $((apcupsd_priority + 10)) $apcupsd_update_every '' '' 'apcupsd'
116 -DIMENSION selftest_OK 'OK' absolute 0 1
117 -DIMENSION selftest_NO 'NO' absolute 0 1
118 -DIMENSION selftest_BT 'BT' absolute 0 1
119 -DIMENSION selftest_NG 'NG' absolute 0 1
116 +DIMENSION selftest_OK 'OK' absolute 1 1
117 +DIMENSION selftest_NO 'NO' absolute 1 1
118 +DIMENSION selftest_BT 'BT' absolute 1 1
119 +DIMENSION selftest_NG 'NG' absolute 1 1
120 +
121 +CHART apcupsd_${host}.status '' "UPS Status" "status" ups apcupsd.status line $((apcupsd_priority + 11)) $apcupsd_update_every '' '' 'apcupsd'
122 +DIMENSION status_ONLINE 'ONLINE' absolute 1 1
123 +DIMENSION status_ONBATT 'ONBATT' absolute 1 1
124 +DIMENSION status_OVERLOAD 'OVERLOAD' absolute 1 1
125 +DIMENSION status_LOWBATT 'LOWBATT' absolute 1 1
126 +DIMENSION status_REPLACEBATT 'REPLACEBATT' absolute 1 1
127 +DIMENSION status_NOBATT 'NOBATT' absolute 1 1
128 +DIMENSION status_SLAVE 'SLAVE' absolute 1 1
129 +DIMENSION status_SLAVEDOWN 'SLAVEDOWN' absolute 1 1
130 +DIMENSION status_COMMLOST 'COMMLOST' absolute 1 1
131 +DIMENSION status_CAL 'CAL' absolute 1 1
132 +DIMENSION status_TRIM 'TRIM' absolute 1 1
133 +DIMENSION status_BOOST 'BOOST' absolute 1 1
134 +DIMENSION status_SHUTTING_DOWN 'SHUTTING_DOWN' absolute 1 1
135
136 EOF
137 done
@@ -136,24 +151,38 @@ apcupsd_update() {
151 apcupsd_get "${apcupsd_sources[${host}]}" | awk "
152
153 BEGIN {
139 - battery_charge = 0;
140 - battery_voltage = 0;
141 - battery_voltage_nominal = 0;
142 - input_voltage = 0;
143 - input_voltage_min = 0;
144 - input_voltage_max = 0;
145 - input_frequency = 0;
146 - output_voltage = 0;
147 - output_voltage_nominal = 0;
148 - load = 0;
149 - temp = 0;
150 - time = 0;
151 - nompower = 0;
152 - load_usage = 0;
153 - selftest_OK = 0;
154 - selftest_NO = 0;
155 - selftest_BT = 0;
156 - selftest_NG = 0;
154 + battery_charge = 0;
155 + battery_voltage = 0;
156 + battery_voltage_nominal = 0;
157 + input_voltage = 0;
158 + input_voltage_min = 0;
159 + input_voltage_max = 0;
160 + input_frequency = 0;
161 + output_voltage = 0;
162 + output_voltage_nominal = 0;
163 + load = 0;
164 + temp = 0;
165 + time = 0;
166 + nompower = 0;
167 + load_usage = 0;
168 + selftest_OK = 0;
169 + selftest_NO = 0;
170 + selftest_BT = 0;
171 + selftest_NG = 0;
172 + status_ONLINE = 0;
173 + status_CAL = 0;
174 + status_TRIM = 0;
175 + status_BOOST = 0;
176 + status_ONBATT = 0;
177 + status_OVERLOAD = 0;
178 + status_LOWBATT = 0;
179 + status_REPLACEBATT = 0;
180 + status_NOBATT = 0;
181 + status_SLAVE = 0;
182 + status_SLAVEDOWN = 0;
183 + status_COMMLOST = 0;
184 + status_SHUTTING_DOWN = 0;
185 +
186 }
187 /^BCHARGE.*/ { battery_charge = \$3 * 100 };
188 /^BATTV.*/ { battery_voltage = \$3 * 100 };
@@ -174,61 +203,92 @@ BEGIN {
203 selftest_BT = (\$3 == \"BT\") ? 1 : 0;
204 selftest_NG = (\$3 == \"NG\") ? 1 : 0;
205 };
206 +/^STATUS.*/ { status_ONLINE = (\$3 == \"ONLINE\") ? 1 : 0;
207 + status_CAL = (\$3 == \"CAL\") ? 1 : 0;
208 + status_TRIM = (\$3 == \"TRIM\") ? 1 : 0;
209 + status_BOOST = (\$3 == \"BOOST\") ? 1 : 0;
210 + status_ONBATT = (\$3 == \"ONBATT\") ? 1 : 0;
211 + status_OVERLOAD = (\$3 == \"OVERLOAD\") ? 1 : 0;
212 + status_LOWBATT = (\$3 == \"LOWBATT\") ? 1 : 0;
213 + status_REPLACEBATT = (\$3 == \"REPLACEBATT\") ? 1 : 0;
214 + status_NOBATT = (\$3 == \"NOBATT\") ? 1 : 0;
215 + status_SLAVE = (\$3 == \"SLAVE\") ? 1 : 0;
216 + status_SLAVEDOWN = (\$3 == \"SLAVEDOWN\") ? 1 : 0;
217 + status_COMMLOST = (\$3 == \"COMMLOST\") ? 1 : 0;
218 + status_SHUTTING_DOWN = (\$3 == \"SHUTTING\" && \$4 == \"DOWN\") ? 1 : 0;
219 + };
220 +
221 END {
178 - { load_usage = nompower * load / 100 };
179 -
180 - print \"BEGIN apcupsd_${host}.online $1\";
181 - print \"SET online = \" online;
182 - print \"END\"
183 -
184 - if (online == 1) {
185 - print \"BEGIN apcupsd_${host}.charge $1\";
186 - print \"SET battery_charge = \" battery_charge;
187 - print \"END\"
188 -
189 - print \"BEGIN apcupsd_${host}.battery_voltage $1\";
190 - print \"SET battery_voltage = \" battery_voltage;
191 - print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
192 - print \"END\"
193 -
194 - print \"BEGIN apcupsd_${host}.input_voltage $1\";
195 - print \"SET input_voltage = \" input_voltage;
196 - print \"SET input_voltage_min = \" input_voltage_min;
197 - print \"SET input_voltage_max = \" input_voltage_max;
198 - print \"END\"
199 -
200 - print \"BEGIN apcupsd_${host}.input_frequency $1\";
201 - print \"SET input_frequency = \" input_frequency;
202 - print \"END\"
203 -
204 - print \"BEGIN apcupsd_${host}.output_voltage $1\";
205 - print \"SET output_voltage = \" output_voltage;
206 - print \"SET output_voltage_nominal = \" output_voltage_nominal;
207 - print \"END\"
208 -
209 - print \"BEGIN apcupsd_${host}.load $1\";
210 - print \"SET load = \" load;
211 - print \"END\"
212 -
213 - print \"BEGIN apcupsd_${host}.load_usage $1\";
214 - print \"SET load_usage = \" load_usage;
215 - print \"END\"
216 -
217 - print \"BEGIN apcupsd_${host}.temp $1\";
218 - print \"SET temp = \" temp;
219 - print \"END\"
220 -
221 - print \"BEGIN apcupsd_${host}.time $1\";
222 - print \"SET time = \" time;
223 - print \"END\"
224 -
225 - print \"BEGIN apcupsd_${host}.selftest $1\";
226 - print \"SET selftest_OK = \" selftest_OK;
227 - print \"SET selftest_NO = \" selftest_NO;
228 - print \"SET selftest_BT = \" selftest_BT;
229 - print \"SET selftest_NG = \" selftest_NG;
230 - print \"END\"
231 - }
222 + { load_usage = nompower * load / 100 };
223 +
224 + print \"BEGIN apcupsd_${host}.online $1\";
225 + print \"SET online = \" online;
226 + print \"END\"
227 +
228 + if (online == 1) {
229 + print \"BEGIN apcupsd_${host}.charge $1\";
230 + print \"SET battery_charge = \" battery_charge;
231 + print \"END\"
232 +
233 + print \"BEGIN apcupsd_${host}.battery_voltage $1\";
234 + print \"SET battery_voltage = \" battery_voltage;
235 + print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
236 + print \"END\"
237 +
238 + print \"BEGIN apcupsd_${host}.input_voltage $1\";
239 + print \"SET input_voltage = \" input_voltage;
240 + print \"SET input_voltage_min = \" input_voltage_min;
241 + print \"SET input_voltage_max = \" input_voltage_max;
242 + print \"END\"
243 +
244 + print \"BEGIN apcupsd_${host}.input_frequency $1\";
245 + print \"SET input_frequency = \" input_frequency;
246 + print \"END\"
247 +
248 + print \"BEGIN apcupsd_${host}.output_voltage $1\";
249 + print \"SET output_voltage = \" output_voltage;
250 + print \"SET output_voltage_nominal = \" output_voltage_nominal;
251 + print \"END\"
252 +
253 + print \"BEGIN apcupsd_${host}.load $1\";
254 + print \"SET load = \" load;
255 + print \"END\"
256 +
257 + print \"BEGIN apcupsd_${host}.load_usage $1\";
258 + print \"SET load_usage = \" load_usage;
259 + print \"END\"
260 +
261 + print \"BEGIN apcupsd_${host}.temp $1\";
262 + print \"SET temp = \" temp;
263 + print \"END\"
264 +
265 + print \"BEGIN apcupsd_${host}.time $1\";
266 + print \"SET time = \" time;
267 + print \"END\"
268 +
269 + print \"BEGIN apcupsd_${host}.selftest $1\";
270 + print \"SET selftest_OK = \" selftest_OK;
271 + print \"SET selftest_NO = \" selftest_NO;
272 + print \"SET selftest_BT = \" selftest_BT;
273 + print \"SET selftest_NG = \" selftest_NG;
274 + print \"END\"
275 +
276 + print \"BEGIN apcupsd_${host}.status $1\";
277 + print \"SET status_ONLINE = \" status_ONLINE;
278 + print \"SET status_ONBATT = \" status_ONBATT;
279 + print \"SET status_OVERLOAD = \" status_OVERLOAD;
280 + print \"SET status_LOWBATT = \" status_LOWBATT;
281 + print \"SET status_REPLACEBATT = \" status_REPLACEBATT;
282 + print \"SET status_NOBATT = \" status_NOBATT;
283 + print \"SET status_SLAVE = \" status_SLAVE;
284 + print \"SET status_SLAVEDOWN = \" status_SLAVEDOWN;
285 + print \"SET status_COMMLOST = \" status_COMMLOST;
286 + print \"SET status_CAL = \" status_CAL;
287 + print \"SET status_TRIM = \" status_TRIM;
288 + print \"SET status_BOOST = \" status_BOOST;
289 + print \"SET status_SHUTTING_DOWN = \" status_SHUTTING_DOWN;
290 + print \"END\";
291 + }
292 }"
293 # shellcheck disable=SC2181
294 if [ $? -ne 0 ]; then
collectors/charts.d.plugin/apcupsd/metadata.yaml
+55
@@ -124,6 +124,34 @@ modules:
124 link: https://github.com/netdata/netdata/blob/master/health/health.d/apcupsd.conf
125 metric: apcupsd.load
126 info: number of seconds since the last successful data collection
127 + - name: apcupsd_selftest_warning
128 + link: https://github.com/netdata/netdata/blob/master/health/health.d/apcupsd.conf
129 + metric: apcupsd.selftest
130 + info: self-test failed due to insufficient battery capacity or due to overload.
131 + - name: apcupsd_status_onbatt
132 + link: https://github.com/netdata/netdata/blob/master/health/health.d/apcupsd.conf
133 + metric: apcupsd.status
134 + info: APC UPS has switched to battery power because the input power has failed
135 + - name: apcupsd_status_overload
136 + link: https://github.com/netdata/netdata/blob/master/health/health.d/apcupsd.conf
137 + metric: apcupsd.status
138 + info: APC UPS is overloaded and cannot supply enough power to the load
139 + - name: apcupsd_status_lowbatt
140 + link: https://github.com/netdata/netdata/blob/master/health/health.d/apcupsd.conf
141 + metric: apcupsd.status
142 + info: APC UPS battery is low and needs to be recharged
143 + - name: apcupsd_status_replacebatt
144 + link: https://github.com/netdata/netdata/blob/master/health/health.d/apcupsd.conf
145 + metric: apcupsd.status
146 + info: APC UPS battery has reached the end of its lifespan and needs to be replaced
147 + - name: apcupsd_status_nobatt
148 + link: https://github.com/netdata/netdata/blob/master/health/health.d/apcupsd.conf
149 + metric: apcupsd.status
150 + info: APC UPS has no battery
151 + - name: apcupsd_status_commlost
152 + link: https://github.com/netdata/netdata/blob/master/health/health.d/apcupsd.conf
153 + metric: apcupsd.status
154 + info: APC UPS communication link is lost
155 metrics:
156 folding:
157 title: Metrics
@@ -199,3 +227,30 @@ modules:
227 chart_type: line
228 dimensions:
229 - name: online
230 + - name: apcupsd.selftest
231 + description: UPS Self-Test status
232 + unit: status
233 + chart_type: line
234 + dimensions:
235 + - name: OK
236 + - name: NO
237 + - name: BT
238 + - name: NG
239 + - name: apcupsd.status
240 + description: UPS Status
241 + unit: status
242 + chart_type: line
243 + dimensions:
244 + - name: ONLINE
245 + - name: ONBATT
246 + - name: OVERLOAD
247 + - name: LOWBATT
248 + - name: REPLACEBATT
249 + - name: NOBATT
250 + - name: SLAVE
251 + - name: SLAVEDOWN
252 + - name: COMMLOST
253 + - name: CAL
254 + - name: TRIM
255 + - name: BOOST
256 + - name: SHUTTING_DOWN
health/health.d/apcupsd.conf
+63
@@ -60,3 +60,66 @@ component: UPS device
60 delay: up 0 down 15m multiplier 1.5 max 1h
61 info: APC UPS self-test failed due to insufficient battery capacity or due to overload.
62 to: sitemgr
63 +
64 +#Send out a warning when STATUS code is ONBATT,OVERLOAD,LOWBATT,REPLACEBATT,NOBATT,COMMLOST
65 +#https://man.archlinux.org/man/apcaccess.8.en#:~:text=apcupsd%20was%20started-,STATUS,-%3A%20UPS%20status.%20One
66 +
67 + template: apcupsd_status_onbatt
68 + on: apcupsd.status
69 + lookup: max -1s unaligned match-names of ONBATT
70 + units: status
71 + every: 10s
72 + warn: $this == 1
73 + delay: up 1m down 15m multiplier 1.5 max 1h
74 + info: APC UPS has switched to battery power because the input power has failed
75 + to: sitemgr
76 +
77 + template: apcupsd_status_overload
78 + on: apcupsd.status
79 + lookup: max -1s unaligned match-names of OVERLOAD
80 + units: status
81 + every: 10s
82 + warn: $this == 1
83 + delay: up 0 down 15m multiplier 1.5 max 1h
84 + info: APC UPS is overloaded and cannot supply enough power to the load
85 + to: sitemgr
86 +
87 + template: apcupsd_status_lowbatt
88 + on: apcupsd.status
89 + lookup: max -1s unaligned match-names of LOWBATT
90 + units: status
91 + every: 10s
92 + warn: $this == 1
93 + delay: up 0 down 15m multiplier 1.5 max 1h
94 + info: APC UPS battery is low and needs to be recharged
95 + to: sitemgr
96 +
97 + template: apcupsd_status_replacebatt
98 + on: apcupsd.status
99 + lookup: max -1s unaligned match-names of REPLACEBATT
100 + units: status
101 + every: 10s
102 + warn: $this == 1
103 + delay: up 0 down 15m multiplier 1.5 max 1h
104 + info: APC UPS battery has reached the end of its lifespan and needs to be replaced
105 + to: sitemgr
106 +
107 + template: apcupsd_status_nobatt
108 + on: apcupsd.status
109 + lookup: max -1s unaligned match-names of NOBATT
110 + units: status
111 + every: 10s
112 + warn: $this == 1
113 + delay: up 0 down 15m multiplier 1.5 max 1h
114 + info: APC UPS has no battery
115 + to: sitemgr
116 +
117 + template: apcupsd_status_commlost
118 + on: apcupsd.status
119 + lookup: max -1s unaligned match-names of COMMLOST
120 + units: status
121 + every: 10s
122 + warn: $this == 1
123 + delay: up 0 down 15m multiplier 1.5 max 1h
124 + info: APC UPS communication link is lost
125 + to: sitemgr