为什么go程序要采集指标?
通过采集指标,可以从外部观测到程序运行中的一些运行中的数据,比如协程数,web请求的接口等情况,从而进一步分析程序是否有不退出的协程,以及性能,是否存在内存泄漏,通过对接Prometheus,能够观测接口请求时间,访问量,访问成功和访问失败等
一、使用
package main
import (
"strconv"
"time"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
router := gin.New()
router.Use(Prometheus())
router.GET("/metrics", gin.WrapH(promhttp.Handler()))
router.GET("/", func(ctx *gin