Refactor: Avoid redundant tag maps

This commit is contained in:
Holger Obermaier 2022-03-11 09:10:14 +01:00
parent c0f59d7d90
commit 0bea1d53a0

@ -104,34 +104,39 @@ func (m *NetstatCollector) Init(config json.RawMessage) error {
// Check if device is a included device // Check if device is a included device
if _, ok := stringArrayContains(m.config.IncludeDevices, dev); ok { if _, ok := stringArrayContains(m.config.IncludeDevices, dev); ok {
tags_unit_byte := map[string]string{"device": dev, "type": "node", "unit": "bytes"}
tags_unit_byte_per_sec := map[string]string{"device": dev, "type": "node", "unit": "bytes/sec"}
tags_unit_pkts := map[string]string{"device": dev, "type": "node", "unit": "packets"}
tags_unit_pkts_per_sec := map[string]string{"device": dev, "type": "node", "unit": "packets/sec"}
m.matches[dev] = []NetstatCollectorMetric{ m.matches[dev] = []NetstatCollectorMetric{
{ {
name: "net_bytes_in", name: "net_bytes_in",
index: fieldReceiveBytes, index: fieldReceiveBytes,
lastValue: 0, lastValue: 0,
tags: map[string]string{"device": dev, "type": "node", "unit": "bytes"}, tags: tags_unit_byte,
rate_tags: map[string]string{"device": dev, "type": "node", "unit": "bytes/sec"}, rate_tags: tags_unit_byte_per_sec,
}, },
{ {
name: "net_pkts_in", name: "net_pkts_in",
index: fieldReceivePackets, index: fieldReceivePackets,
lastValue: 0, lastValue: 0,
tags: map[string]string{"device": dev, "type": "node", "unit": "packets"}, tags: tags_unit_pkts,
rate_tags: map[string]string{"device": dev, "type": "node", "unit": "packets/sec"}, rate_tags: tags_unit_pkts_per_sec,
}, },
{ {
name: "net_bytes_out", name: "net_bytes_out",
index: fieldTransmitBytes, index: fieldTransmitBytes,
lastValue: 0, lastValue: 0,
tags: map[string]string{"device": dev, "type": "node", "unit": "bytes"}, tags: tags_unit_byte,
rate_tags: map[string]string{"device": dev, "type": "node", "unit": "bytes/sec"}, rate_tags: tags_unit_byte_per_sec,
}, },
{ {
name: "net_pkts_out", name: "net_pkts_out",
index: fieldTransmitPackets, index: fieldTransmitPackets,
lastValue: 0, lastValue: 0,
tags: map[string]string{"device": dev, "type": "node", "unit": "packets"}, tags: tags_unit_pkts,
rate_tags: map[string]string{"device": dev, "type": "node", "unit": "packets/sec"}, rate_tags: tags_unit_pkts_per_sec,
}, },
} }
} }