mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
FrontendMetrics: Adds new backend api that frontend can use to push frontend measurements and counters to prometheus (#32593)
* FrontendMetrics: Adds new backend api that frontend can use to push frontend measurements and counters to prometheus * FrontendMetrics: Adds new backend api that frontend can use to push frontend measurements and counters to prometheus * Fix naming * change to histogram * Fixed go lint
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/frontendlogging"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
@@ -397,6 +398,8 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
annotationsRoute.Post("/graphite", reqEditorRole, bind(dtos.PostGraphiteAnnotationsCmd{}), routing.Wrap(PostGraphiteAnnotation))
|
||||
})
|
||||
|
||||
apiRoute.Post("/frontend-metrics", bind(metrics.PostFrontendMetricsCommand{}), routing.Wrap(hs.PostFrontendMetrics))
|
||||
|
||||
if hs.Live.IsEnabled() {
|
||||
apiRoute.Post("/live/publish", bind(dtos.LivePublishCmd{}), routing.Wrap(hs.Live.HandleHTTPPublish))
|
||||
}
|
||||
|
||||
21
pkg/api/frontend_metrics.go
Normal file
21
pkg/api/frontend_metrics.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
func (hs *HTTPServer) PostFrontendMetrics(c *models.ReqContext, cmd metrics.PostFrontendMetricsCommand) response.Response {
|
||||
for _, event := range cmd.Events {
|
||||
name := strings.Replace(event.Name, "-", "_", -1)
|
||||
if recorder, ok := metrics.FrontendMetrics[name]; ok {
|
||||
recorder(event)
|
||||
} else {
|
||||
c.Logger.Debug("Received unknown frontend metric", "metric", name)
|
||||
}
|
||||
}
|
||||
return response.Empty(200)
|
||||
}
|
||||
Reference in New Issue
Block a user