erigon-pulse/metrics/exp/exp.go
Alex Sharov ad72b7178e
prune speedup. stage_senders: don't re-calc existing senders (#7643)
- stage_senders: don't re-calc existing senders
- stage_tx_lookup: prune less blocks per iteration - because
random-deletes are expensive. pruning must not slow-down sync.
- prune data even if --snap.stop is set
- "prune as-much-as-possible at startup" is not very good idea: at
initialCycle machine can be cold and prune will cause big downtime, no
reason to produce much freelist in 1 tx. People may also restart erigon
- because of some bug - and it will cause unexpected downtime (usually
Erigon startup very fast). So, I just remove all `initialSync`-related
logic in pruning.
- fix lost metrics about disk write byte/sec
2023-06-03 12:30:53 +07:00

42 lines
1.3 KiB
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 exp
import (
"fmt"
"net/http"
metrics2 "github.com/VictoriaMetrics/metrics"
"github.com/ledgerwatch/log/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/expfmt"
)
// Setup starts a dedicated metrics server at the given address.
// This function enables metrics reporting separate from pprof.
func Setup(address string) {
http.HandleFunc("/debug/metrics/prometheus", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
metrics2.WritePrometheus(w, true)
contentType := expfmt.Negotiate(r.Header)
enc := expfmt.NewEncoder(w, contentType)
mf, err := prometheus.DefaultGatherer.Gather()
if err != nil {
return
}
for _, m := range mf {
enc.Encode(m)
}
})
//m.Handle("/debug/metrics", ExpHandler(metrics.DefaultRegistry))
//http.Handle("/debug/metrics/prometheus2", promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{}))
log.Info("Starting metrics server", "addr",
fmt.Sprintf("http://%s/debug/metrics/prometheus", address),
)
go func() {
if err := http.ListenAndServe(address, nil); err != nil { // nolint:gosec
log.Error("Failure in running metrics server", "err", err)
}
}()
}