3 Star 5 Fork 6

三三物联网/ssiot-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
metrics.go 1020 Bytes
一键复制 编辑 原始数据 按行查看 历史
三三物联网 提交于 2年前 . 重构
/*
* @Author: lwnmengjing
* @Date: 2021/6/9 5:57 下午
* @Last Modified by: lwnmengjing
* @Last Modified time: 2021/6/9 5:57 下午
*/
package middleware
import (
"context"
"github.com/gin-gonic/gin"
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
"github.com/slok/go-http-metrics/middleware"
)
// Metrics returns a Gin measuring middleware.
func Metrics() gin.HandlerFunc {
handlerID := ""
m := middleware.New(middleware.Config{
Recorder: metrics.NewRecorder(metrics.Config{}),
})
return func(c *gin.Context) {
r := &reporter{c: c}
m.Measure(handlerID, r, func() {
c.Next()
})
}
}
type reporter struct {
c *gin.Context
}
func (r *reporter) Method() string { return r.c.Request.Method }
func (r *reporter) Context() context.Context { return r.c.Request.Context() }
func (r *reporter) URLPath() string {
return r.c.FullPath()
}
func (r *reporter) StatusCode() int { return r.c.Writer.Status() }
func (r *reporter) BytesWritten() int64 { return int64(r.c.Writer.Size()) }
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sansaniot/ssiot-core.git
git@gitee.com:sansaniot/ssiot-core.git
sansaniot
ssiot-core
ssiot-core
v1.8.33

搜索帮助