add status code to request duration metric

This commit is contained in:
Marco Jantke 2017-06-15 16:06:02 +02:00 committed by Ludovic Fernandez
parent 34e60a8404
commit 0055965295
3 changed files with 9 additions and 5 deletions

View file

@ -42,9 +42,12 @@ func (m *MetricsWrapper) ServeHTTP(rw http.ResponseWriter, r *http.Request, next
start := time.Now()
prw := &responseRecorder{rw, http.StatusOK}
next(prw, r)
labels := []string{"code", strconv.Itoa(prw.statusCode), "method", r.Method}
m.Impl.getReqsCounter().With(labels...).Add(1)
m.Impl.getReqDurationHistogram().Observe(float64(time.Since(start).Seconds()))
reqLabels := []string{"code", strconv.Itoa(prw.statusCode), "method", r.Method}
m.Impl.getReqsCounter().With(reqLabels...).Add(1)
reqDurationLabels := []string{"code", strconv.Itoa(prw.statusCode)}
m.Impl.getReqDurationHistogram().With(reqDurationLabels...).Observe(float64(time.Since(start).Seconds()))
}
// MetricsRetryListener is an implementation of the RetryListener interface to