erigon-pulse/metrics/exp.go
Mark Holt 8ea0096d56
moved metrics sub packages types to metrics (#8119)
This is a non functional change which consolidates the various packages
under metrics into the top level package now that the dead code is
removed.

It is a precursor to the removal of Victoria metrics after which all
erigon metrics code will be contained in this single package.
2023-09-03 08:09:27 +07:00

34 lines
900 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"
)
// 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 {
log.Error("Failure in running Prometheus server", "err", err)
}
}()
log.Info("Enabling metrics export to prometheus", "path", fmt.Sprintf("http://%s/debug/metrics/prometheus", address))
return prometheusMux
}