Move unit tag to meta data tags

This commit is contained in:
Holger Obermaier 2022-03-11 14:47:18 +01:00
parent 0b08ca9ae0
commit 992b19d354

View File

@ -22,11 +22,12 @@ type NetstatCollectorConfig struct {
} }
type NetstatCollectorMetric struct { type NetstatCollectorMetric struct {
name string name string
index int index int
tags map[string]string tags map[string]string
rate_tags map[string]string meta map[string]string
lastValue int64 meta_rates map[string]string
lastValue int64
} }
type NetstatCollector struct { type NetstatCollector struct {
@ -40,10 +41,6 @@ func (m *NetstatCollector) Init(config json.RawMessage) error {
m.name = "NetstatCollector" m.name = "NetstatCollector"
m.setup() m.setup()
m.lastTimestamp = time.Now() m.lastTimestamp = time.Now()
m.meta = map[string]string{
"source": m.name,
"group": "Network",
}
const ( const (
fieldInterface = iota fieldInterface = iota
@ -104,39 +101,44 @@ 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 := map[string]string{"device": dev, "type": "node"}
tags_unit_byte_per_sec := map[string]string{"device": dev, "type": "node", "unit": "bytes/sec"} meta_unit_byte := map[string]string{"source": m.name, "group": "Network", "unit": "bytes"}
tags_unit_pkts := map[string]string{"device": dev, "type": "node", "unit": "packets"} meta_unit_byte_per_sec := map[string]string{"source": m.name, "group": "Network", "unit": "bytes/sec"}
tags_unit_pkts_per_sec := map[string]string{"device": dev, "type": "node", "unit": "packets/sec"} meta_unit_pkts := map[string]string{"source": m.name, "group": "Network", "unit": "packets"}
meta_unit_pkts_per_sec := map[string]string{"source": m.name, "group": "Network", "unit": "packets/sec"}
m.matches[dev] = []NetstatCollectorMetric{ m.matches[dev] = []NetstatCollectorMetric{
{ {
name: "net_bytes_in", name: "net_bytes_in",
index: fieldReceiveBytes, index: fieldReceiveBytes,
lastValue: -1, lastValue: -1,
tags: tags_unit_byte, tags: tags,
rate_tags: tags_unit_byte_per_sec, meta: meta_unit_byte,
meta_rates: meta_unit_byte_per_sec,
}, },
{ {
name: "net_pkts_in", name: "net_pkts_in",
index: fieldReceivePackets, index: fieldReceivePackets,
lastValue: -1, lastValue: -1,
tags: tags_unit_pkts, tags: tags,
rate_tags: tags_unit_pkts_per_sec, meta: meta_unit_pkts,
meta_rates: meta_unit_pkts_per_sec,
}, },
{ {
name: "net_bytes_out", name: "net_bytes_out",
index: fieldTransmitBytes, index: fieldTransmitBytes,
lastValue: -1, lastValue: -1,
tags: tags_unit_byte, tags: tags,
rate_tags: tags_unit_byte_per_sec, meta: meta_unit_byte,
meta_rates: meta_unit_byte_per_sec,
}, },
{ {
name: "net_pkts_out", name: "net_pkts_out",
index: fieldTransmitPackets, index: fieldTransmitPackets,
lastValue: -1, lastValue: -1,
tags: tags_unit_pkts, tags: tags,
rate_tags: tags_unit_pkts_per_sec, meta: meta_unit_pkts,
meta_rates: meta_unit_pkts_per_sec,
}, },
} }
} }
@ -194,14 +196,14 @@ func (m *NetstatCollector) Read(interval time.Duration, output chan lp.CCMetric)
continue continue
} }
if m.config.SendAbsoluteValues { if m.config.SendAbsoluteValues {
if y, err := lp.New(metric.name, metric.tags, m.meta, map[string]interface{}{"value": v}, now); err == nil { if y, err := lp.New(metric.name, metric.tags, metric.meta, map[string]interface{}{"value": v}, now); err == nil {
output <- y output <- y
} }
} }
if m.config.SendDerivedValues { if m.config.SendDerivedValues {
if metric.lastValue >= 0 { if metric.lastValue >= 0 {
rate := float64(v-metric.lastValue) / timeDiff rate := float64(v-metric.lastValue) / timeDiff
if y, err := lp.New(metric.name+"_bw", metric.rate_tags, m.meta, map[string]interface{}{"value": rate}, now); err == nil { if y, err := lp.New(metric.name+"_bw", metric.tags, metric.meta_rates, map[string]interface{}{"value": rate}, now); err == nil {
output <- y output <- y
} }
} }