mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-08-18 08:22:59 +02:00
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:
@@ -2,6 +2,7 @@ package sinks
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -11,28 +12,44 @@ import (
|
||||
influx "github.com/influxdata/line-protocol"
|
||||
)
|
||||
|
||||
type HttpSinkConfig struct {
|
||||
defaultSinkConfig
|
||||
Host string `json:"host,omitempty"`
|
||||
Port string `json:"port,omitempty"`
|
||||
Database string `json:"database,omitempty"`
|
||||
JWT string `json:"jwt,omitempty"`
|
||||
SSL bool `json:"ssl,omitempty"`
|
||||
}
|
||||
|
||||
type HttpSink struct {
|
||||
sink
|
||||
client *http.Client
|
||||
url, jwt string
|
||||
encoder *influx.Encoder
|
||||
buffer *bytes.Buffer
|
||||
config HttpSinkConfig
|
||||
}
|
||||
|
||||
func (s *HttpSink) Init(config sinkConfig) error {
|
||||
func (s *HttpSink) Init(config json.RawMessage) error {
|
||||
s.name = "HttpSink"
|
||||
if len(config.Host) == 0 || len(config.Port) == 0 || len(config.Database) == 0 {
|
||||
s.config.SSL = false
|
||||
if len(config) > 0 {
|
||||
err := json.Unmarshal(config, &s.config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(s.config.Host) == 0 || len(s.config.Port) == 0 || len(s.config.Database) == 0 {
|
||||
return errors.New("`host`, `port` and `database` config options required for TCP sink")
|
||||
}
|
||||
|
||||
s.client = &http.Client{}
|
||||
proto := "http"
|
||||
if config.SSL {
|
||||
if s.config.SSL {
|
||||
proto = "https"
|
||||
}
|
||||
s.url = fmt.Sprintf("%s://%s:%s/%s", proto, config.Host, config.Port, config.Database)
|
||||
s.port = config.Port
|
||||
s.jwt = config.Password
|
||||
s.url = fmt.Sprintf("%s://%s:%s/%s", proto, s.config.Host, s.config.Port, s.config.Database)
|
||||
s.jwt = s.config.JWT
|
||||
s.buffer = &bytes.Buffer{}
|
||||
s.encoder = influx.NewEncoder(s.buffer)
|
||||
s.encoder.SetPrecision(time.Second)
|
||||
|
Reference in New Issue
Block a user