Sink specific configuration maps (#25)

* Use sink-specific configurations to have more flexibility. Adjust sample sink configuration files

* Add documentation

* Add links to individual sink readmes

* Fix link in README

* HTTPS for HttpSink

* If no CPU die id available, use the socket id instead
This commit is contained in:
Thomas Gruber
2022-02-04 18:12:24 +01:00
committed by GitHub
parent f719f1915c
commit fdb58b0be2
16 changed files with 431 additions and 185 deletions

View File

@@ -1,6 +1,8 @@
package sinks
import (
"encoding/json"
"errors"
"fmt"
"log"
"strings"
@@ -8,20 +10,49 @@ import (
// "time"
"os/exec"
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
)
const GMETRIC_EXEC = `gmetric`
type GangliaSink struct {
Sink
gmetric_path string
type GangliaSinkConfig struct {
defaultSinkConfig
GmetricPath string `json:"gmetric_path"`
AddGangliaGroup bool `json:"add_ganglia_group"`
}
func (s *GangliaSink) Init(config sinkConfig) error {
p, err := exec.LookPath(string(GMETRIC_EXEC))
if err == nil {
s.gmetric_path = p
type GangliaSink struct {
sink
gmetric_path string
config GangliaSinkConfig
}
func (s *GangliaSink) Init(config json.RawMessage) error {
var err error = nil
s.name = "GangliaSink"
if len(config) > 0 {
err := json.Unmarshal(config, &s.config)
if err != nil {
cclog.ComponentError(s.name, "Error reading config for", s.name, ":", err.Error())
return err
}
}
s.gmetric_path = ""
if len(s.config.GmetricPath) > 0 {
p, err := exec.LookPath(s.config.GmetricPath)
if err == nil {
s.gmetric_path = p
}
}
if len(s.gmetric_path) == 0 {
p, err := exec.LookPath(string(GMETRIC_EXEC))
if err == nil {
s.gmetric_path = p
}
}
if len(s.gmetric_path) == 0 {
err = errors.New("cannot find executable 'gmetric'")
}
return err
}
@@ -37,11 +68,29 @@ func (s *GangliaSink) Write(point lp.CCMetric) error {
case "unit":
argstr = append(argstr, fmt.Sprintf("--units=%s", value))
case "group":
argstr = append(argstr, fmt.Sprintf("--group=%s", value))
if s.config.AddGangliaGroup {
argstr = append(argstr, fmt.Sprintf("--group=%s", value))
}
default:
tagsstr = append(tagsstr, fmt.Sprintf("%s=%s", key, value))
}
}
if s.config.MetaAsTags {
for key, value := range point.Meta() {
switch key {
case "cluster":
argstr = append(argstr, fmt.Sprintf("--cluster=%s", value))
case "unit":
argstr = append(argstr, fmt.Sprintf("--units=%s", value))
case "group":
if s.config.AddGangliaGroup {
argstr = append(argstr, fmt.Sprintf("--group=%s", value))
}
default:
tagsstr = append(tagsstr, fmt.Sprintf("%s=%s", key, value))
}
}
}
if len(tagsstr) > 0 {
argstr = append(argstr, fmt.Sprintf("--desc=%q", strings.Join(tagsstr, ",")))
}