mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
78596a6756
Fixes #30144 Co-authored-by: dsotirakis <sotirakis.dim@gmail.com> Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com> Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> Co-authored-by: Leon Sorokin <leeoniya@gmail.com> Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com> Co-authored-by: spinillos <selenepinillos@gmail.com> Co-authored-by: Karl Persson <kalle.persson@grafana.com> Co-authored-by: Leonard Gram <leo@xlson.com>
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package metrics
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/infra/metrics/graphitebridge"
|
|
"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()
|
|
initFrontendMetrics()
|
|
}
|
|
|
|
func ProvideService(cfg *setting.Cfg) (*InternalMetricsService, error) {
|
|
s := &InternalMetricsService{
|
|
Cfg: cfg,
|
|
}
|
|
return s, s.readSettings()
|
|
}
|
|
|
|
type InternalMetricsService struct {
|
|
Cfg *setting.Cfg
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
MInstanceStart.Inc()
|
|
|
|
<-ctx.Done()
|
|
return ctx.Err()
|
|
}
|