erigon-pulse/metrics/exp.go
Mark Holt 0d190ff9e9
Bor rpc config fix (#8413)
This is an additional fix for BorRo to add bor config in the constructor
- otherwise code which accesses chain config will panic.
2023-10-10 15:26:02 +01: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
}