improve(go.d/snmp): add transform for Host-Resources-MIB storage metrics (#20957)
Ilya Mashchenko committed
Sep 11, 2025 at 14:55 UTC
e402ddb7ab8b8bde996429d39150509f6f588069
3 files changed
+61
-20
src/go/plugin/go.d/collector/snmp/ddsnmp/transform.go
+49
@@ -269,6 +269,55 @@ func newMetricTransformFuncMap() template.FuncMap {
269
}
270
}
271
272
+ return ""
273
+ },
274
+ "transformHrStorage": func(m *Metric) string {
275
+ // hrStorageType → friendly name/family
276
+ // https://oidref.com/1.3.6.1.2.1.25.2.1
277
+ typeMap := map[string]map[string]string{
278
+ "1.3.6.1.2.1.25.2.1.1": {"key": "other", "family": "System/Memory/Other", "desc": "Other memory"},
279
+ "1.3.6.1.2.1.25.2.1.2": {"key": "ram", "family": "System/Memory/RAM", "desc": "Physical system memory"},
280
+ "1.3.6.1.2.1.25.2.1.3": {"key": "virtual_memory", "family": "System/Memory/Swap", "desc": "Virtual memory space"},
281
+ "1.3.6.1.2.1.25.2.1.4": {"key": "fixed_disk", "family": "System/Storage/Disk", "desc": "Fixed disk storage"},
282
+ "1.3.6.1.2.1.25.2.1.5": {"key": "removable_disk", "family": "System/Storage/Removable", "desc": "Removable disk storage"},
283
+ "1.3.6.1.2.1.25.2.1.6": {"key": "floppy", "family": "System/Storage/Removable", "desc": "Floppy disk storage"},
284
+ "1.3.6.1.2.1.25.2.1.7": {"key": "cdrom", "family": "System/Storage/Removable", "desc": "CD-ROM storage"},
285
+ "1.3.6.1.2.1.25.2.1.8": {"key": "ram_disk", "family": "System/Storage/RAMDisk", "desc": "RAM-based storage"},
286
+ "1.3.6.1.2.1.25.2.1.9": {"key": "flash", "family": "System/Storage/Flash", "desc": "Flash-based storage"},
287
+ "1.3.6.1.2.1.25.2.1.10": {"key": "network_disk", "family": "System/Storage/NetworkDisk", "desc": "Network-mounted storage"},
288
+ }
289
+
290
+ storageTypeOID := m.Tags["rm:storage_type"]
291
+ allocUnit, _ := strconv.ParseInt(m.Tags["rm:storage_alloc_unit"], 10, 64)
292
+
293
+ if storageTypeOID == "" || allocUnit <= 0 || m.Value < 0 {
294
+ return ""
295
+ }
296
+
297
+ tconf, ok := typeMap[storageTypeOID]
298
+ if !ok {
299
+ tconf = map[string]string{"key": "unknown", "family": "System/Storage/Unknown", "desc": "Unknown storage type"}
300
+ }
301
+
302
+ bytesVal := m.Value * allocUnit // to bytes
303
+ baseKey := tconf["key"]
304
+ fam := tconf["family"]
305
+ desc := tconf["desc"]
306
+
307
+ switch m.Name {
308
+ case "hrStorageSize":
309
+ m.Family = fam + "/Total"
310
+ m.Description = desc + " - Total"
311
+ case "hrStorageUsed":
312
+ m.Family = fam + "/Used"
313
+ m.Description = desc + " - Used"
314
+ default:
315
+ return ""
316
+ }
317
+
318
+ m.Name = m.Name + "_" + baseKey
319
+ m.Value = bytesVal
320
+
321
return ""
322
},
323
}
src/go/plugin/go.d/config/go.d/snmp.profiles/default/_std-host-resources-mib-feat-base.yaml
+6
-10
@@ -57,23 +57,15 @@ metrics:
57
- OID: 1.3.6.1.2.1.25.2.3.1.5
58
name: hrStorageSize
59
chart_meta:
60
- description: Total size of the storage area
61
- family: 'System/Storage/Total'
60
unit: "By"
61
transform: |
64
- {{- $unit := index .Metric.Tags "rm:storage_alloc_unit" | default "1024" -}}
65
- {{- $factor := int64 $unit -}}
66
- {{- setValue .Metric (mul .Metric.Value $factor) -}}
62
+ {{- transformHrStorage .Metric -}}
63
- OID: 1.3.6.1.2.1.25.2.3.1.6
64
name: hrStorageUsed
65
chart_meta:
70
- description: Amount of storage used
71
- family: 'System/Storage/Used'
66
unit: "By"
67
transform: |
74
- {{- $unit := index .Metric.Tags "rm:storage_alloc_unit" | default "1024" -}}
75
- {{- $factor := int64 $unit -}}
76
- {{- setValue .Metric (mul .Metric.Value $factor) -}}
68
+ {{- transformHrStorage .Metric -}}
69
metric_tags:
70
- tag: storage_index
71
index: 1
@@ -81,6 +73,10 @@ metrics:
73
symbol:
74
OID: 1.3.6.1.2.1.25.2.3.1.3
75
name: hrDeviceDescr
76
+ - tag: rm:storage_type # Needed for transformation
77
+ symbol:
78
+ OID: 1.3.6.1.2.1.25.2.3.1.2
79
+ name: hrStorageType
80
- tag: rm:storage_alloc_unit # Needed for transformation
81
symbol:
82
OID: 1.3.6.1.2.1.25.2.3.1.4
src/go/plugin/go.d/config/go.d/snmp.profiles/default/mikrotik-router.yaml
+6
-10
@@ -229,23 +229,15 @@ metrics:
229
- OID: 1.3.6.1.2.1.25.2.3.1.5
230
name: memory.total
231
chart_meta:
232
- description: Total size of the storage in bytes
233
- family: 'System/Memory/Total'
232
unit: "By"
233
transform: |
236
- {{- $unit := index .Metric.Tags "rm:storage_alloc_unit" | default "1" -}}
237
- {{- $factor := int64 $unit -}}
238
- {{- setValue .Metric (mul .Metric.Value $factor) -}}
234
+ {{- transformHrStorage .Metric -}}
235
- OID: 1.3.6.1.2.1.25.2.3.1.6
236
name: memory.used
237
chart_meta:
242
- description: Amount of storage currently allocated in bytes
243
- family: 'System/Memory/Used'
238
unit: "By"
239
transform: |
246
- {{- $unit := index .Metric.Tags "rm:storage_alloc_unit" | default "1" -}}
247
- {{- $factor := int64 $unit -}}
248
- {{- setValue .Metric (mul .Metric.Value $factor) -}}
240
+ {{- transformHrStorage .Metric -}}
241
metric_tags:
242
- tag: mem_index
243
index: 1
@@ -253,6 +245,10 @@ metrics:
245
symbol:
246
OID: 1.3.6.1.2.1.25.2.3.1.3
247
name: hrStorageDescr
248
+ - tag: rm:storage_type # Needed for transformation
249
+ symbol:
250
+ OID: 1.3.6.1.2.1.25.2.3.1.2
251
+ name: hrStorageType
252
- tag: rm:storage_alloc_unit # Needed for transformation
253
symbol:
254
OID: 1.3.6.1.2.1.25.2.3.1.4