From b0b46991ecdd6eae14410c7109f18a9f29f6b4c0 Mon Sep 17 00:00:00 2001 From: Carl Bergquist Date: Wed, 19 Feb 2020 18:29:47 +0100 Subject: [PATCH] Metrics: Add gauge for requests currently in flight (#22168) Add gauge for requests currently in flight. Co-authored-by: Marcus Efraimsson --- pkg/middleware/request_metrics.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/middleware/request_metrics.go b/pkg/middleware/request_metrics.go index d3657e6abd0..9bbf5e37f04 100644 --- a/pkg/middleware/request_metrics.go +++ b/pkg/middleware/request_metrics.go @@ -7,13 +7,32 @@ import ( "time" "github.com/grafana/grafana/pkg/infra/metrics" + "github.com/prometheus/client_golang/prometheus" "gopkg.in/macaron.v1" ) +var ( + httpRequestsInFlight prometheus.Gauge +) + +func init() { + httpRequestsInFlight = prometheus.NewGauge( + prometheus.GaugeOpts{ + Name: "http_request_in_flight", + Help: "A gauge of requests currently being served by Grafana.", + }, + ) + + prometheus.MustRegister(httpRequestsInFlight) +} + +// RequestMetrics is a middleware handler that instruments the request func RequestMetrics(handler string) macaron.Handler { return func(res http.ResponseWriter, req *http.Request, c *macaron.Context) { rw := res.(macaron.ResponseWriter) now := time.Now() + httpRequestsInFlight.Inc() + defer httpRequestsInFlight.Dec() c.Next() status := rw.Status()