Add request_duration_seconds metric
This commit is contained in:
@@ -58,13 +58,18 @@ func (rl *rushlink) recoveryMiddleware(next http.Handler) http.Handler {
|
||||
|
||||
func (rl *rushlink) metricsMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
tick := time.Now()
|
||||
srw := statusResponseWriter{Inner: w}
|
||||
next.ServeHTTP(&srw, r)
|
||||
tock := time.Now()
|
||||
|
||||
status := strconv.Itoa(srw.StatusCode)
|
||||
labels := map[string]string{"code": status, "method": r.Method}
|
||||
// Update requests counter metric
|
||||
metricRequestsTotalCounter.With(labels).Inc()
|
||||
// Update request latency metric
|
||||
elapsed := tock.Sub(tick)
|
||||
metricRequestsLatencyNanoSeconds.With(labels).Observe(elapsed.Seconds())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user