From f91e91bb71ff05abd54cb3e90d95e2370f9e165e Mon Sep 17 00:00:00 2001 From: Ilya Mashchenko Date: Thu, 25 Apr 2024 14:34:53 +0300 Subject: go.d prometheus fix units for snmp_exporter (#17524) --- .../collectors/go.d.plugin/modules/prometheus/charts.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/go/collectors/go.d.plugin/modules/prometheus/charts.go b/src/go/collectors/go.d.plugin/modules/prometheus/charts.go index 61e8031d75..72d93020e2 100644 --- a/src/go/collectors/go.d.plugin/modules/prometheus/charts.go +++ b/src/go/collectors/go.d.plugin/modules/prometheus/charts.go @@ -280,6 +280,21 @@ func getChartUnits(metric string) string { idx := strings.LastIndexByte(metric, '_') if idx == -1 { + // snmp_exporter: e.g. ifOutUcastPkts, ifOutOctets. + if idx = strings.LastIndexFunc(metric, func(r rune) bool { return r >= 'A' && r <= 'Z' }); idx != -1 { + v := strings.ToLower(metric[idx:]) + switch v { + case "pkts": + return "packets" + case "octets": + return "bytes" + case "mtu": + return "octets" + case "speed": + return "bits" + } + return v + } return "events" } switch suffix := metric[idx:]; suffix { -- cgit v1.2.3