2022-10-12 18:42:05 +02:00
|
|
|
package controller
|
|
|
|
|
2022-10-13 20:23:52 +02:00
|
|
|
import (
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2022-10-12 18:42:05 +02:00
|
|
|
type MetricsConfig struct {
|
2022-10-13 21:50:12 +02:00
|
|
|
ServiceName string
|
|
|
|
Influx *InfluxConfig
|
2022-10-12 18:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type InfluxConfig struct {
|
|
|
|
Url string
|
|
|
|
Bucket string
|
|
|
|
Org string
|
|
|
|
Token string
|
|
|
|
}
|
2022-10-13 20:23:52 +02:00
|
|
|
|
|
|
|
type metricsAgent struct {
|
2022-10-13 21:50:12 +02:00
|
|
|
cfg *MetricsConfig
|
|
|
|
shutdown chan struct{}
|
|
|
|
joined chan struct{}
|
2022-10-13 20:23:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func newMetricsAgent(cfg *MetricsConfig) *metricsAgent {
|
2022-10-13 21:50:12 +02:00
|
|
|
return &metricsAgent{
|
|
|
|
cfg: cfg,
|
|
|
|
shutdown: make(chan struct{}),
|
|
|
|
joined: make(chan struct{}),
|
|
|
|
}
|
2022-10-13 20:23:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mtr *metricsAgent) run() {
|
|
|
|
logrus.Info("starting")
|
|
|
|
defer logrus.Info("exiting")
|
2022-10-13 21:50:12 +02:00
|
|
|
defer close(mtr.joined)
|
2022-10-13 20:23:52 +02:00
|
|
|
|
2022-10-13 21:50:12 +02:00
|
|
|
<-mtr.shutdown
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mtr *metricsAgent) stop() {
|
|
|
|
close(mtr.shutdown)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mtr *metricsAgent) join() {
|
|
|
|
<-mtr.joined
|
2022-10-13 20:23:52 +02:00
|
|
|
}
|