From 4e0782d66b9eb3ea221ec68e32703962d935ca58 Mon Sep 17 00:00:00 2001 From: Holger Obermaier <40787752+ho-ob@users.noreply.github.com> Date: Tue, 8 Feb 2022 10:58:53 +0100 Subject: [PATCH] Use FromInfluxMetric() to convert influx to cc metric --- collectors/customCmdMetric.go | 6 ++++-- collectors/metricCollector.go | 19 ------------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/collectors/customCmdMetric.go b/collectors/customCmdMetric.go index ffe8b73..483d2ba 100644 --- a/collectors/customCmdMetric.go +++ b/collectors/customCmdMetric.go @@ -9,6 +9,7 @@ import ( "strings" "time" + ccmetric "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric" lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric" influx "github.com/influxdata/line-protocol" ) @@ -97,7 +98,8 @@ func (m *CustomCmdCollector) Read(interval time.Duration, output chan lp.CCMetri if skip { continue } - y, err := lp.New(c.Name(), Tags2Map(c), m.meta, Fields2Map(c), c.Time()) + + y := ccmetric.FromInfluxMetric(c) if err == nil { output <- y } @@ -119,7 +121,7 @@ func (m *CustomCmdCollector) Read(interval time.Duration, output chan lp.CCMetri if skip { continue } - y, err := lp.New(f.Name(), Tags2Map(f), m.meta, Fields2Map(f), f.Time()) + y := ccmetric.FromInfluxMetric(f) if err == nil { output <- y } diff --git a/collectors/metricCollector.go b/collectors/metricCollector.go index 3484dca..c71ae16 100644 --- a/collectors/metricCollector.go +++ b/collectors/metricCollector.go @@ -10,7 +10,6 @@ import ( "time" lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric" - influx "github.com/influxdata/line-protocol" ) type MetricCollector interface { @@ -115,24 +114,6 @@ func CpuList() []int { return cpulist } -// Tags2Map stores a InfluxDB list of tags in a map of key value pairs -func Tags2Map(metric influx.Metric) map[string]string { - tags := make(map[string]string) - for _, t := range metric.TagList() { - tags[t.Key] = t.Value - } - return tags -} - -// Fields2Map stores a InfluxDB list of fields in a map of key value pairs -func Fields2Map(metric influx.Metric) map[string]interface{} { - fields := make(map[string]interface{}) - for _, f := range metric.FieldList() { - fields[f.Key] = f.Value - } - return fields -} - // RemoveFromStringList removes the string r from the array of strings s // If r is not contained in the array an error is returned func RemoveFromStringList(s []string, r string) ([]string, error) {