2021-05-18 15:15:26 +02:00
|
|
|
package receivers
|
|
|
|
|
|
|
|
import (
|
|
|
|
// "time"
|
2022-01-25 15:37:43 +01:00
|
|
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
2021-05-18 15:15:26 +02:00
|
|
|
influx "github.com/influxdata/line-protocol"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ReceiverConfig struct {
|
2022-01-25 15:37:43 +01:00
|
|
|
Addr string `json:"address"`
|
|
|
|
Port string `json:"port"`
|
|
|
|
Database string `json:"database"`
|
|
|
|
Organization string `json:"organization,omitempty"`
|
|
|
|
Type string `json:"type"`
|
2021-05-18 15:15:26 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 15:37:43 +01:00
|
|
|
type receiver struct {
|
2021-05-18 15:44:42 +02:00
|
|
|
name string
|
2021-05-18 15:15:26 +02:00
|
|
|
addr string
|
|
|
|
port string
|
|
|
|
database string
|
|
|
|
organization string
|
2022-01-25 15:37:43 +01:00
|
|
|
sink chan lp.CCMetric
|
2021-05-18 15:15:26 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 15:37:43 +01:00
|
|
|
type Receiver interface {
|
|
|
|
Init(config ReceiverConfig) error
|
2021-05-18 15:15:26 +02:00
|
|
|
Start()
|
|
|
|
Close()
|
2022-01-25 15:37:43 +01:00
|
|
|
Name() string
|
|
|
|
SetSink(sink chan lp.CCMetric)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *receiver) Name() string {
|
|
|
|
return r.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *receiver) SetSink(sink chan lp.CCMetric) {
|
|
|
|
r.sink = sink
|
2021-05-18 15:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|