Use common functions in both Ganglia sinks

This commit is contained in:
Thomas Roehl
2022-02-18 15:05:45 +01:00
parent e2f78fe1c0
commit d9a81501e5
3 changed files with 73 additions and 29 deletions

View File

@@ -69,7 +69,6 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"unsafe"
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
@@ -109,23 +108,6 @@ type LibgangliaSink struct {
cstrCache map[string]*C.char
}
func gangliaMetricName(point lp.CCMetric) string {
name := point.Name()
metricType, typeOK := point.GetTag("type")
metricTid, tidOk := point.GetTag("type-id")
gangliaType := metricType + metricTid
if strings.Contains(name, metricType) && tidOk {
name = strings.Replace(name, metricType, gangliaType, -1)
} else if typeOK && tidOk {
name = metricType + metricTid + "_" + name
} else if point.HasTag("device") {
device, _ := point.GetTag("device")
name = name + "_" + device
}
return name
}
func (s *LibgangliaSink) Init(config json.RawMessage) error {
var err error = nil
s.name = "LibgangliaSink"
@@ -197,9 +179,9 @@ func (s *LibgangliaSink) Write(point lp.CCMetric) error {
}
// Get metric name
metricname := point.Name()
metricname := GangliaMetricRename(point)
if s.config.AddTypeToName {
c_name = lookup(gangliaMetricName(point))
c_name = lookup(GangliaMetricName(point))
} else {
c_name = lookup(metricname)
}
@@ -247,11 +229,10 @@ func (s *LibgangliaSink) Write(point lp.CCMetric) error {
// Determine the slope of the metric. Ganglia's own collector mostly use
// 'both' but the mem and swap total uses 'zero'.
slope := GangliaSlopeType(point)
slope_type := C.GANGLIA_SLOPE_BOTH
switch metricname {
case "mem_total":
slope_type = C.GANGLIA_SLOPE_ZERO
case "swap_total":
switch slope {
case 0:
slope_type = C.GANGLIA_SLOPE_ZERO
}