improve(go.d/snmp): dd support for non-identifying tags in table metrics (#20530)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Ilya Mashchenko committed
Jun 20, 2025 at 10:18 UTC
4817991c3e5e9e1b37c802a7cad89ee2e631d83e
4 files changed
+12
-7
src/go/plugin/go.d/collector/snmp/charts.go
+4
-1
@@ -395,7 +395,10 @@ func (c *Collector) addProfileTableMetricChart(m ddsnmp.Metric) {
395
"sysName": c.sysInfo.Name,
396
}
397
maps.Copy(tags, m.Profile.Tags)
398
- maps.Copy(tags, m.Tags)
398
+ for k, v := range m.Tags {
399
+ newKey := strings.TrimPrefix(k, "_")
400
+ tags[newKey] = v
401
+ }
402
403
for k, v := range tags {
404
chart.Labels = append(chart.Labels, module.Label{Key: k, Value: v})
src/go/plugin/go.d/collector/snmp/collect_profiles.go
+4
-2
@@ -67,6 +67,7 @@ func (c *Collector) collectProfileTableMetrics(mx map[string]int64, pms []*ddsnm
67
}
68
69
key := tableMetricKey(m)
70
+
71
seen[key] = true
72
73
if !c.seenTableMetrics[key] {
@@ -103,10 +104,11 @@ func tableMetricKey(m ddsnmp.Metric) string {
104
var sb strings.Builder
105
106
sb.WriteString(m.Name)
107
+
108
for _, k := range keys {
107
- if v := m.Tags[k]; v != "" {
109
+ if v := m.Tags[k]; v != "" && !strings.HasPrefix(k, "_") {
110
sb.WriteString("_")
109
- sb.WriteString(m.Tags[k])
111
+ sb.WriteString(v)
112
}
113
}
114
src/go/plugin/go.d/config/go.d/snmp.profiles/default/_generic-if.yaml
+2
-2
@@ -66,7 +66,7 @@ metrics:
66
symbol:
67
OID: 1.3.6.1.2.1.2.2.1.2
68
name: ifDescr
69
- - tag: if_type
69
+ - tag: _if_type
70
symbol:
71
OID: 1.3.6.1.2.1.2.2.1.3
72
name: ifType
@@ -134,7 +134,7 @@ metrics:
134
symbol:
135
OID: 1.3.6.1.2.1.2.2.1.2
136
name: ifDescr
137
- - tag: if_type
137
+ - tag: _if_type
138
table: ifTable
139
symbol:
140
OID: 1.3.6.1.2.1.2.2.1.3
src/go/plugin/go.d/config/go.d/snmp.profiles/default/mikrotik-router.yaml
+2
-2
@@ -158,7 +158,7 @@ metrics:
158
scale_factor: 1024
159
unit: "By"
160
metric_tags:
161
- - tag: mem_index
161
+ - tag: _mem_index
162
index: 1
163
- tag: mem
164
symbol:
@@ -199,7 +199,7 @@ metrics:
199
200
{{- if $config -}}
201
{{- setName .Metric (printf "%s_%s" .Metric.Name (get $config "name")) -}}
202
- {{- setFamily .Metric (printf "Health/Sensors/%s" (get $config "family")) -}}
202
+ {{- setFamily .Metric (printf "Sensors/%s" (get $config "family")) -}}
203
{{- with get $config "desc" -}}{{- setDesc $.Metric . -}}{{- end -}}
204
{{- with get $config "unit" -}}{{- setUnit $.Metric . -}}{{- end -}}
205
{{- with get $config "divisor" -}}{{- setValue $.Metric (int64 (div (float64 $.Value) .)) -}}{{- end -}}