added reusable metrics endpoints

This commit is contained in:
Evgeniy Kulikov 2020-03-03 13:34:52 +03:00
parent 1d5c1897a3
commit ad03a95feb
No known key found for this signature in database
GPG key ID: BF6AEE0A2A699BF2

View file

@ -3,12 +3,25 @@ package main
import ( import (
"fmt" "fmt"
"github.com/fasthttp/router"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
) )
func attachMetrics(r *router.Router, z promhttp.Logger) {
r.GET("/metrics/", metricsHandler(prometheus.DefaultGatherer, promhttp.HandlerOpts{
ErrorLog: z,
//ErrorHandling: 0,
//Registry: nil,
//DisableCompression: false,
//MaxRequestsInFlight: 0,
//Timeout: 0,
//EnableOpenMetrics: false,
}))
}
func metricsHandler(reg prometheus.Gatherer, opts promhttp.HandlerOpts) fasthttp.RequestHandler { func metricsHandler(reg prometheus.Gatherer, opts promhttp.HandlerOpts) fasthttp.RequestHandler {
var ( var (
inFlightSem chan struct{} inFlightSem chan struct{}