2018-05-02 12:54:07 -05:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-05-13 01:45:54 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
2019-02-23 16:35:26 -06:00
|
|
|
"github.com/grafana/grafana/pkg/infra/metrics/graphitebridge"
|
2018-05-02 12:54:07 -05:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
)
|
|
|
|
|
|
|
|
var metricsLogger log.Logger = log.New("metrics")
|
|
|
|
|
|
|
|
type logWrapper struct {
|
|
|
|
logger log.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (lw *logWrapper) Println(v ...interface{}) {
|
|
|
|
lw.logger.Info("graphite metric bridge", v...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
initMetricVars()
|
2021-04-01 13:04:02 -05:00
|
|
|
initFrontendMetrics()
|
2018-05-02 12:54:07 -05:00
|
|
|
}
|
|
|
|
|
2021-08-25 08:11:22 -05:00
|
|
|
func ProvideService(cfg *setting.Cfg) (*InternalMetricsService, error) {
|
|
|
|
s := &InternalMetricsService{
|
|
|
|
Cfg: cfg,
|
|
|
|
}
|
|
|
|
return s, s.readSettings()
|
|
|
|
}
|
|
|
|
|
2018-05-02 12:54:07 -05:00
|
|
|
type InternalMetricsService struct {
|
2021-08-25 08:11:22 -05:00
|
|
|
Cfg *setting.Cfg
|
2018-05-02 12:54:07 -05:00
|
|
|
|
|
|
|
intervalSeconds int64
|
|
|
|
graphiteCfg *graphitebridge.Config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (im *InternalMetricsService) Run(ctx context.Context) error {
|
|
|
|
// Start Graphite Bridge
|
|
|
|
if im.graphiteCfg != nil {
|
|
|
|
bridge, err := graphitebridge.NewBridge(im.graphiteCfg)
|
|
|
|
if err != nil {
|
|
|
|
metricsLogger.Error("failed to create graphite bridge", "error", err)
|
|
|
|
} else {
|
|
|
|
go bridge.Run(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 09:58:46 -05:00
|
|
|
MInstanceStart.Inc()
|
2018-05-02 12:54:07 -05:00
|
|
|
|
2019-02-07 06:13:01 -06:00
|
|
|
<-ctx.Done()
|
|
|
|
return ctx.Err()
|
2018-05-02 12:54:07 -05:00
|
|
|
}
|