update
This commit is contained in:
28
myhttp/httpsr/middleware.go
Normal file
28
myhttp/httpsr/middleware.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package httpsr
|
||||
|
||||
import (
|
||||
"git.makemake.in/kzkzzzz/mycommon/mymetric"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"time"
|
||||
)
|
||||
|
||||
func QPSCollect(svcName string) gin.HandlerFunc {
|
||||
hs := mymetric.NewQPSHistogram(svcName, []string{
|
||||
"svc", "method", "route", "from",
|
||||
}...)
|
||||
|
||||
return func(ctx *gin.Context) {
|
||||
st := time.Now()
|
||||
|
||||
ctx.Next()
|
||||
|
||||
hs.With(prometheus.Labels{
|
||||
"svc": svcName,
|
||||
"method": ctx.Request.Method,
|
||||
"route": ctx.Request.URL.Path,
|
||||
"form": "",
|
||||
}).Observe(float64(time.Since(st).Milliseconds()))
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user