github.com/weedge/lib@v0.0.0-20230424045628-a36dcc1d90e4/metric/prometheus_http.go (about)

     1  package metric
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/gin-gonic/gin"
     7  	"github.com/prometheus/client_golang/prometheus/promhttp"
     8  )
     9  
    10  // grafana dashboard https://grafana.com/grafana/dashboards/10826
    11  func HttpMetrics(handler http.Handler) {
    12  	switch r := handler.(type) {
    13  	case *gin.Engine:
    14  		h := promhttp.Handler()
    15  		r.GET("/metrics", func(c *gin.Context) {
    16  			h.ServeHTTP(c.Writer, c.Request)
    17  		})
    18  	}
    19  
    20  }