From 81fc6582a0d177488ee02ef5c81b32b1558898a7 Mon Sep 17 00:00:00 2001 From: Srivatsa Srinivasan Date: Mon, 13 Jan 2020 18:02:34 -0800 Subject: [PATCH] Have prometheus emit status code strings not the actual status text --- middleware.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/middleware.go b/middleware.go index 121d73f..c42c247 100644 --- a/middleware.go +++ b/middleware.go @@ -3,6 +3,7 @@ package chiprometheus import ( "net/http" + "strconv" "time" "github.com/go-chi/chi/middleware" @@ -53,8 +54,8 @@ func (c Middleware) handler(next http.Handler) http.Handler { start := time.Now() ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor) next.ServeHTTP(ww, r) - c.reqs.WithLabelValues(http.StatusText(ww.Status()), r.Method, r.URL.Path).Inc() - c.latency.WithLabelValues(http.StatusText(ww.Status()), r.Method, r.URL.Path).Observe(float64(time.Since(start).Nanoseconds()) / 1000000) + c.reqs.WithLabelValues(strconv.Itoa(ww.Status()), r.Method, r.URL.Path).Inc() + c.latency.WithLabelValues(strconv.Itoa(ww.Status()), r.Method, r.URL.Path).Observe(float64(time.Since(start).Nanoseconds()) / 1000000) } return http.HandlerFunc(fn) }