erigon-pulse/erigon-lib/metrics/setup.go

36 lines
948 B
Go
Raw Normal View History

package metrics
import (
"fmt"
"net/http"
2021-07-29 10:23:23 +00:00
"github.com/ledgerwatch/log/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var EnabledExpensive = false
// Setup starts a dedicated metrics server at the given address.
// This function enables metrics reporting separate from pprof.
func Setup(address string, logger log.Logger) *http.ServeMux {
prometheus.DefaultRegisterer.MustRegister(defaultSet)
prometheusMux := http.NewServeMux()
prometheusMux.Handle("/debug/metrics/prometheus", promhttp.Handler())
promServer := &http.Server{
Addr: address,
Handler: prometheusMux,
}
go func() {
if err := promServer.ListenAndServe(); err != nil {
logger.Error("Failure in running Prometheus server", "err", err)
}
}()
logger.Info("Enabling metrics export to prometheus", "path", fmt.Sprintf("http://%s/debug/metrics/prometheus", address))
return prometheusMux
}