go.d prometheus fix units for snmp_exporter (#17524)
Ilya Mashchenko committed
Apr 25, 2024 at 14:34 UTC
f91e91bb71ff05abd54cb3e90d95e2370f9e165e
1 file changed
+15
src/go/collectors/go.d.plugin/modules/prometheus/charts.go
+15
@@ -280,6 +280,21 @@ func getChartUnits(metric string) string {
280
281
idx := strings.LastIndexByte(metric, '_')
282
if idx == -1 {
283
+ // snmp_exporter: e.g. ifOutUcastPkts, ifOutOctets.
284
+ if idx = strings.LastIndexFunc(metric, func(r rune) bool { return r >= 'A' && r <= 'Z' }); idx != -1 {
285
+ v := strings.ToLower(metric[idx:])
286
+ switch v {
287
+ case "pkts":
288
+ return "packets"
289
+ case "octets":
290
+ return "bytes"
291
+ case "mtu":
292
+ return "octets"
293
+ case "speed":
294
+ return "bits"
295
+ }
296
+ return v
297
+ }
298
return "events"
299
}
300
switch suffix := metric[idx:]; suffix {