erigon-pulse/metrics/exp/exp.go

31 lines
1.1 KiB
Go
Raw Normal View History

// Hook go-metrics into expvar
// on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler
package exp
import (
"fmt"
"net/http"
2021-07-29 10:27:46 +00:00
metrics2 "github.com/VictoriaMetrics/metrics"
2021-07-29 10:23:23 +00:00
"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) {
2021-07-29 10:27:46 +00:00
http.HandleFunc("/debug/metrics/prometheus", func(w http.ResponseWriter, r *http.Request) {
2022-03-09 18:40:53 +00:00
w.Header().Set("Access-Control-Allow-Origin", "*")
2021-07-29 10:27:46 +00:00
metrics2.WritePrometheus(w, true)
})
//m.Handle("/debug/metrics", ExpHandler(metrics.DefaultRegistry))
//m.Handle("/debug/metrics/prometheus2", promhttp.HandlerFor(prometheus2.DefaultGatherer, promhttp.HandlerOpts{
// EnableOpenMetrics: true,
//}))
log.Info("Starting metrics server", "addr", fmt.Sprintf("http://%s/debug/metrics/prometheus", address))
go func() {
2021-07-29 10:27:46 +00:00
if err := http.ListenAndServe(address, nil); err != nil {
log.Error("Failure in running metrics server", "err", err)
}
}()
}