Adjust ganglia sink to CCMetric

This commit is contained in:
Thomas Roehl 2022-01-30 15:25:57 +01:00
parent d915bcc02d
commit 011218ab80

View File

@ -2,11 +2,13 @@ package sinks
import ( import (
"fmt" "fmt"
"log"
"strings" "strings"
"log"
// "time" // "time"
lp "github.com/influxdata/line-protocol"
"os/exec" "os/exec"
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
) )
const GMETRIC_EXEC = `gmetric` const GMETRIC_EXEC = `gmetric`
@ -16,59 +18,59 @@ type GangliaSink struct {
gmetric_path string gmetric_path string
} }
func (s *GangliaSink) Init(config SinkConfig) error { func (s *GangliaSink) Init(config sinkConfig) error {
p, err := exec.LookPath(string(GMETRIC_EXEC)) p, err := exec.LookPath(string(GMETRIC_EXEC))
if err == nil { if err == nil {
s.gmetric_path = p s.gmetric_path = p
} }
return err return err
} }
func (s *GangliaSink) Write(point lp.MutableMetric) error { func (s *GangliaSink) Write(point lp.CCMetric) error {
var err error = nil var err error = nil
var tagsstr []string var tagsstr []string
var argstr []string var argstr []string
for _, t := range point.TagList() { for _, t := range point.TagList() {
switch t.Key { switch t.Key {
case "cluster": case "cluster":
argstr = append(argstr, fmt.Sprintf("--cluster=%s", t.Value)) argstr = append(argstr, fmt.Sprintf("--cluster=%s", t.Value))
case "unit": case "unit":
argstr = append(argstr, fmt.Sprintf("--units=%s", t.Value)) argstr = append(argstr, fmt.Sprintf("--units=%s", t.Value))
case "group": case "group":
argstr = append(argstr, fmt.Sprintf("--group=%s", t.Value)) argstr = append(argstr, fmt.Sprintf("--group=%s", t.Value))
default: default:
tagsstr = append(tagsstr, fmt.Sprintf("%s=%s", t.Key, t.Value)) tagsstr = append(tagsstr, fmt.Sprintf("%s=%s", t.Key, t.Value))
} }
} }
if len(tagsstr) > 0 { if len(tagsstr) > 0 {
argstr = append(argstr, fmt.Sprintf("--desc=%q", strings.Join(tagsstr, ","))) argstr = append(argstr, fmt.Sprintf("--desc=%q", strings.Join(tagsstr, ",")))
} }
argstr = append(argstr, fmt.Sprintf("--name=%s", point.Name())) argstr = append(argstr, fmt.Sprintf("--name=%s", point.Name()))
for _, f := range point.FieldList() { for _, f := range point.FieldList() {
if f.Key == "value" { if f.Key == "value" {
switch f.Value.(type) { switch f.Value.(type) {
case float64: case float64:
argstr = append(argstr, fmt.Sprintf("--value=%v", f.Value.(float64))) argstr = append(argstr, fmt.Sprintf("--value=%v", f.Value.(float64)))
argstr = append(argstr, "--type=double") argstr = append(argstr, "--type=double")
case float32: case float32:
argstr = append(argstr, fmt.Sprintf("--value=%v", f.Value.(float32))) argstr = append(argstr, fmt.Sprintf("--value=%v", f.Value.(float32)))
argstr = append(argstr, "--type=float") argstr = append(argstr, "--type=float")
case int: case int:
argstr = append(argstr, fmt.Sprintf("--value=%d", f.Value.(int))) argstr = append(argstr, fmt.Sprintf("--value=%d", f.Value.(int)))
argstr = append(argstr, "--type=int32") argstr = append(argstr, "--type=int32")
case int64: case int64:
argstr = append(argstr, fmt.Sprintf("--value=%d", f.Value.(int64))) argstr = append(argstr, fmt.Sprintf("--value=%d", f.Value.(int64)))
argstr = append(argstr, "--type=int32") argstr = append(argstr, "--type=int32")
case string: case string:
argstr = append(argstr, fmt.Sprintf("--value=%q", f.Value.(string))) argstr = append(argstr, fmt.Sprintf("--value=%q", f.Value.(string)))
argstr = append(argstr, "--type=string") argstr = append(argstr, "--type=string")
} }
} }
} }
log.Print(s.gmetric_path, " ", strings.Join(argstr, " ")) log.Print(s.gmetric_path, " ", strings.Join(argstr, " "))
// command := exec.Command(string(GMETRIC_EXEC), strings.Join(argstr, " ")) // command := exec.Command(string(GMETRIC_EXEC), strings.Join(argstr, " "))
// command.Wait() // command.Wait()
// _, err := command.Output() // _, err := command.Output()
return err return err
} }
@ -77,5 +79,4 @@ func (s *GangliaSink) Flush() error {
} }
func (s *GangliaSink) Close() { func (s *GangliaSink) Close() {
return
} }