update
parent
4ced8ae869
commit
a545116f52
|
@ -5,6 +5,7 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -73,11 +74,24 @@ const (
|
|||
)
|
||||
|
||||
// 监控指标路由
|
||||
func GinExport(engine *gin.Engine) {
|
||||
engine.GET(MetricsRoute, gin.WrapH(promhttp.HandlerFor(
|
||||
func GinExport(authKey string) gin.HandlerFunc {
|
||||
pm := promhttp.HandlerFor(
|
||||
prometheus.DefaultGatherer,
|
||||
promhttp.HandlerOpts{Timeout: time.Second * 3},
|
||||
)))
|
||||
)
|
||||
|
||||
return func(ctx *gin.Context) {
|
||||
if authKey != "" {
|
||||
value := ctx.Query("key")
|
||||
if authKey != value {
|
||||
ctx.String(http.StatusForbidden, "metric auth key is empty")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
pm.ServeHTTP(ctx.Writer, ctx.Request)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func HistogramKey(name string) string {
|
||||
|
|
Loading…
Reference in New Issue