2021-05-18 15:15:26 +02:00
|
|
|
package receivers
|
|
|
|
|
|
|
|
import (
|
2024-12-19 23:00:14 +01:00
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
lp "github.com/ClusterCockpit/cc-energy-manager/pkg/cc-message"
|
|
|
|
mp "github.com/ClusterCockpit/cc-metric-collector/pkg/messageProcessor"
|
2021-05-18 15:15:26 +02:00
|
|
|
)
|
|
|
|
|
2022-02-21 12:45:08 +01:00
|
|
|
type defaultReceiverConfig struct {
|
2024-12-19 23:00:14 +01:00
|
|
|
Type string `json:"type"`
|
|
|
|
MessageProcessor json.RawMessage `json:"process_messages,omitempty"`
|
2022-02-21 12:45:08 +01:00
|
|
|
}
|
|
|
|
|
2022-02-28 12:16:48 +01:00
|
|
|
// Receiver configuration: Listen address, port
|
2021-05-18 15:15:26 +02:00
|
|
|
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 {
|
2022-02-22 16:33:38 +01:00
|
|
|
name string
|
2024-12-19 23:00:14 +01:00
|
|
|
sink chan lp.CCMessage
|
|
|
|
mp mp.MessageProcessor
|
2021-05-18 15:15:26 +02:00
|
|
|
}
|
|
|
|
|
2022-01-25 15:37:43 +01:00
|
|
|
type Receiver interface {
|
2021-05-18 15:15:26 +02:00
|
|
|
Start()
|
2024-12-19 23:00:14 +01:00
|
|
|
Close() // Close / finish metric receiver
|
|
|
|
Name() string // Name of the metric receiver
|
|
|
|
SetSink(sink chan lp.CCMessage) // Set sink channel
|
2022-01-25 15:37:43 +01:00
|
|
|
}
|
|
|
|
|
2022-02-28 12:16:48 +01:00
|
|
|
// Name returns the name of the metric receiver
|
2022-01-25 15:37:43 +01:00
|
|
|
func (r *receiver) Name() string {
|
|
|
|
return r.name
|
|
|
|
}
|
|
|
|
|
2022-02-28 12:16:48 +01:00
|
|
|
// SetSink set the sink channel
|
2024-12-19 23:00:14 +01:00
|
|
|
func (r *receiver) SetSink(sink chan lp.CCMessage) {
|
2022-01-25 15:37:43 +01:00
|
|
|
r.sink = sink
|
2021-05-18 15:15:26 +02:00
|
|
|
}
|