1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 05:10:54 +00:00

Merge pull request #4023 from flycash/feature/prometheus

Change prometheus patter
This commit is contained in:
askuy 2020-06-21 17:39:02 +08:00 committed by GitHub
commit 6e4d0917b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,14 +28,15 @@ import (
func PrometheusMiddleWare(next http.Handler) http.Handler { func PrometheusMiddleWare(next http.Handler) http.Handler {
summaryVec := prometheus.NewSummaryVec(prometheus.SummaryOpts{ summaryVec := prometheus.NewSummaryVec(prometheus.SummaryOpts{
Name: beego.BConfig.AppName, Name: "beego",
Subsystem: "http_request", Subsystem: "http_request",
ConstLabels: map[string]string{ ConstLabels: map[string]string{
"server": beego.BConfig.ServerName, "server": beego.BConfig.ServerName,
"env": beego.BConfig.RunMode, "env": beego.BConfig.RunMode,
"appname": beego.BConfig.AppName,
}, },
Help: "The statics info for http request", Help: "The statics info for http request",
}, []string{"pattern", "method", "status"}) }, []string{"pattern", "method", "status", "duration"})
prometheus.MustRegister(summaryVec) prometheus.MustRegister(summaryVec)
@ -68,5 +69,6 @@ func report(dur time.Duration, writer http.ResponseWriter, q *http.Request, vec
} else { } else {
logs.Warn("we can not find the router info for this request, so request will be recorded as UNKNOWN: " + q.URL.String()) logs.Warn("we can not find the router info for this request, so request will be recorded as UNKNOWN: " + q.URL.String())
} }
vec.WithLabelValues(ptn, q.Method, strconv.Itoa(status)).Observe(float64(dur / time.Millisecond)) ms := dur / time.Millisecond
vec.WithLabelValues(ptn, q.Method, strconv.Itoa(status), strconv.Itoa(int(ms))).Observe(float64(ms))
} }