From 46889970711bf575f6d33cf25ee064cba3de50bc Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Fri, 8 Oct 2021 13:28:02 +0200 Subject: [PATCH] Add two helper functions to collector definition --- collectors/metricCollector.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/collectors/metricCollector.go b/collectors/metricCollector.go index d05b443..14c72ec 100644 --- a/collectors/metricCollector.go +++ b/collectors/metricCollector.go @@ -116,3 +116,19 @@ func CpuList() []int { } return cpulist } + +func Tags2Map(metric lp.Metric) map[string]string { + tags := make(map[string]string) + for _, t := range metric.TagList() { + tags[t.Key] = t.Value + } + return tags +} + +func Fields2Map(metric lp.Metric) map[string]interface{} { + fields := make(map[string]interface{}) + for _, f := range metric.FieldList() { + fields[f.Key] = f.Value + } + return fields +}