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
e *gin.Engine
e.GET("metrics", prom.PromHandler(promhttp.Handler()))
启动项目,访问 /metrics
包含了一些内置指标,比如 gc 等等。下一步就可以配置接入 prometheus server,grafana 配置界面了
grafana dashboard
Original: https://www.cnblogs.com/stulzq/p/16091202.html
Author: 晓晨Master
Title: Go gin 接入 prometheus
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/590235/
转载文章受原作者版权保护。转载请注明原作者出处!