代码拉取完成,页面将自动刷新
package prometheus
import (
"gitee.com/mosache/YFrame/rest"
"github.com/prometheus/client_golang/prometheus"
"strconv"
"time"
)
type MiddlewareBuilder struct {
Namespace string
Subsystem string
Name string
Help string
}
func (m MiddlewareBuilder) Build() rest.MiddleWare {
vector := prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: m.Namespace,
Subsystem: m.Subsystem,
Name: m.Name,
Help: m.Help,
Objectives: map[float64]float64{
0.5: 0.01,
0.75: 0.01,
0.90: 0.01,
0.99: 0.001,
0.999: 0.0001,
},
}, []string{"pattern", "method", "status"})
prometheus.MustRegister(vector)
return func(next rest.HandleFunc) rest.HandleFunc {
return func(ctx *rest.Context) {
st := time.Now()
defer func() {
duration := time.Now().Sub(st).Milliseconds()
pattern := ctx.MatchedRoute
if pattern == "" {
pattern = "unknown"
}
vector.WithLabelValues(pattern, ctx.Req.Method, strconv.Itoa(ctx.RespStatusCode)).Observe(float64(duration))
}()
next(ctx)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。