chore: coding style, add code for prometheus (#4002)
This commit is contained in:
@@ -17,7 +17,7 @@ var (
|
||||
Subsystem: "requests",
|
||||
Name: "duration_ms",
|
||||
Help: "http server requests duration(ms).",
|
||||
Labels: []string{"path", "method"},
|
||||
Labels: []string{"path", "method", "code"},
|
||||
Buckets: []float64{5, 10, 25, 50, 100, 250, 500, 750, 1000},
|
||||
})
|
||||
|
||||
@@ -26,7 +26,7 @@ var (
|
||||
Subsystem: "requests",
|
||||
Name: "code_total",
|
||||
Help: "http server requests error count.",
|
||||
Labels: []string{"path", "code", "method"},
|
||||
Labels: []string{"path", "method", "code"},
|
||||
})
|
||||
)
|
||||
|
||||
@@ -37,8 +37,9 @@ func PrometheusHandler(path, method string) func(http.Handler) http.Handler {
|
||||
startTime := timex.Now()
|
||||
cw := response.NewWithCodeResponseWriter(w)
|
||||
defer func() {
|
||||
metricServerReqDur.Observe(timex.Since(startTime).Milliseconds(), path, method)
|
||||
metricServerReqCodeTotal.Inc(path, strconv.Itoa(cw.Code), method)
|
||||
code := strconv.Itoa(cw.Code)
|
||||
metricServerReqDur.Observe(timex.Since(startTime).Milliseconds(), path, method, code)
|
||||
metricServerReqCodeTotal.Inc(path, method, code)
|
||||
}()
|
||||
|
||||
next.ServeHTTP(cw, r)
|
||||
|
||||
Reference in New Issue
Block a user