|
|
@ -18,7 +18,7 @@ var (
|
|
|
|
Subsystem: "requests",
|
|
|
|
Subsystem: "requests",
|
|
|
|
Name: "duration_ms",
|
|
|
|
Name: "duration_ms",
|
|
|
|
Help: "http server requests duration(ms).",
|
|
|
|
Help: "http server requests duration(ms).",
|
|
|
|
Labels: []string{"path"},
|
|
|
|
Labels: []string{"path", "method"},
|
|
|
|
Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 1000},
|
|
|
|
Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 1000},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
@ -27,19 +27,19 @@ var (
|
|
|
|
Subsystem: "requests",
|
|
|
|
Subsystem: "requests",
|
|
|
|
Name: "code_total",
|
|
|
|
Name: "code_total",
|
|
|
|
Help: "http server requests error count.",
|
|
|
|
Help: "http server requests error count.",
|
|
|
|
Labels: []string{"path", "code"},
|
|
|
|
Labels: []string{"path", "code", "method"},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// PrometheusHandler returns a middleware that reports stats to prometheus.
|
|
|
|
// PrometheusHandler returns a middleware that reports stats to prometheus.
|
|
|
|
func PrometheusHandler(path string) func(http.Handler) http.Handler {
|
|
|
|
func PrometheusHandler(path, method string) func(http.Handler) http.Handler {
|
|
|
|
return func(next http.Handler) http.Handler {
|
|
|
|
return func(next http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
startTime := timex.Now()
|
|
|
|
startTime := timex.Now()
|
|
|
|
cw := &response.WithCodeResponseWriter{Writer: w}
|
|
|
|
cw := &response.WithCodeResponseWriter{Writer: w}
|
|
|
|
defer func() {
|
|
|
|
defer func() {
|
|
|
|
metricServerReqDur.Observe(int64(timex.Since(startTime)/time.Millisecond), path)
|
|
|
|
metricServerReqDur.Observe(int64(timex.Since(startTime)/time.Millisecond), path, method)
|
|
|
|
metricServerReqCodeTotal.Inc(path, strconv.Itoa(cw.Code))
|
|
|
|
metricServerReqCodeTotal.Inc(path, strconv.Itoa(cw.Code), method)
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
next.ServeHTTP(cw, r)
|
|
|
|
next.ServeHTTP(cw, r)
|
|
|
|