Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from Remitly/http-response-codes-not-strings
Browse files Browse the repository at this point in the history
Have prometheus emit status code strings not the actual status text
  • Loading branch information
remitly-srivatsa committed Jan 15, 2020
2 parents f25f242 + 81fc658 commit b4be448
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package chiprometheus

import (
"net/http"
"strconv"
"time"

"github.com/go-chi/chi/middleware"
Expand Down Expand Up @@ -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)
}

0 comments on commit b4be448

Please sign in to comment.