grafana/pkg/api/frontend_metrics.go
Torkel Ödegaard d42a5b2561
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
2021-04-01 20:04:02 +02:00

22 lines
579 B
Go

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)
}