Go gin 接入 prometheus

Java69

Prometheus 的 go sdk 是由官方提供的,地址:https://github.com/prometheus/client_golang ,里面包含了生成 prometheus metrics、http handler、prometheus client 的功能。

安装:

go get github.com/prometheus/client_golang

编写 gin handle

func PromHandler(handler http.Handler) gin.HandlerFunc {
    return func(c *gin.Context) {
        handler.ServeHTTP(c.Writer, c.Request)
    }
}

配置 route

输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长