com.snow.auto_monitor/app/http/middlewares/metric.go

23 lines
437 B
Go
Raw Normal View History

2024-07-12 18:11:21 +08:00
package middlewares
import (
"time"
"com.snow.auto_monitor/app/http/metric"
"github.com/gin-gonic/gin"
)
func CollectMetric() gin.HandlerFunc {
return func(ctx *gin.Context) {
start := time.Now()
ctx.Next()
dur := time.Now().Sub(start).Milliseconds()
metric.AddAllReqCount(ctx.Request)
metric.CollectAllReqCostTime(ctx.Request, dur)
metric.AddReqCount(ctx.Request)
metric.CollectReqCostTime(ctx.Request, dur)
}
}