erigon-pulse/erigon-lib/metrics/exp.go
a 436493350e
Sentinel refactor (#8296)
1. changes sentinel to use an http-like interface

2. moves hexutil, crypto/blake2b, metrics packages to erigon-lib
2023-10-22 01:17:18 +02:00

36 lines
936 B
Go

// Hook go-metrics into expvar
// on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler
package metrics
import (
"fmt"
"net/http"
"github.com/ledgerwatch/log/v3"
)
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 {
prometheusMux := http.NewServeMux()
prometheusMux.Handle("/debug/metrics/prometheus", Handler(DefaultRegistry))
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
}