Refactor metric collection

This commit is contained in:
Daan Sprenkels
2021-05-16 20:21:44 +02:00
parent 4f07bc4c2a
commit a26894dac8
2 changed files with 56 additions and 30 deletions

View File

@@ -60,8 +60,11 @@ func (rl *rushlink) metricsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srw := statusResponseWriter{Inner: w}
next.ServeHTTP(&srw, r)
status := strconv.Itoa(srw.StatusCode)
metricRequestsTotalCounter.WithLabelValues(status, r.Method).Inc()
labels := map[string]string{"code": status, "method": r.Method}
// Update requests counter metric
metricRequestsTotalCounter.With(labels).Inc()
})
}