关于micro:go-micro-metrics-接入PrometheusGrafana
本文介绍go micro中退出metric, 并接入Prometheus、Grafana 1.go micro中间件加载prometheus pluginsgo micro中提供了prometheus plugins github.com/micro/go-plugins/wrapper/monitoring/prometheus/ package mainimport ( "net/http" "github.com/micro/go-plugins/wrapper/monitoring/prometheus/v2" "github.com/prometheus/client_golang/prometheus/promhttp" //...)func main() { // New Service service := micro.NewService( micro.Name("go.micro.api.myauth"), micro.Version("latest"), micro.WrapHandler(prometheus.NewHandlerWrapper()), ) // Initialise service service.Init( // create wrap for the Myauth service client micro.WrapHandler(client.MyauthWrapper(service)), ) go PrometheusBoot() // Register Handler myauth.RegisterMyauthHandler(service.Server(), new(handler.Myauth)) // Run service if err := service.Run(); err != nil { log.Fatal(err) }}func PrometheusBoot() { http.Handle("/metrics", promhttp.Handler()) // 启动web服务,监听8085端口 go func() { err := http.ListenAndServe("localhost:8085", nil) if err != nil { log.Fatal("ListenAndServe: ", err) } }()}代码很简略,在micro.NewService中传入micro.WrapHandler(prometheus.NewHandlerWrapper()), ...