erigon-pulse/diagnostics/header_downloader_stats.go
Mark Holt a4cfbe0d56
Heimdall metrics + Metrics HTTP server rationalization (#8094)
This is an update of:

https://github.com/ledgerwatch/erigon/pull/7846

which uses a local fork of victoria metrics to include the changes that
https://github.com/anshalshukla added to the original for we where
using.

It also includes code to address the duplicate metrics issue identified
here:

https://github.com/ledgerwatch/erigon/issues/8053

It has one more associated fix which is to correctly add a metadata
label to counters, these where previously labelled as gauges.

e.g. 

```
# TYPE p2p_peers counter
p2p_peers 0
```
rather than

```
# TYPE p2p_peers gauge
p2p_peers 0
```

---------

Co-authored-by: Anshal Shukla <53994948+anshalshukla@users.noreply.github.com>
Co-authored-by: Anshal Shukla <shukla.anshal85@gmail.com>
2023-08-31 09:04:27 +01:00

36 lines
907 B
Go

package diagnostics
import (
"fmt"
"io"
"net/http"
"strconv"
"github.com/ledgerwatch/erigon/dataflow"
)
func SetupHeaderDownloadStats(metricsMux *http.ServeMux) {
metricsMux.HandleFunc("/debug/metrics/headers_download", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
writeHeaderDownload(w, r)
})
}
func writeHeaderDownload(w io.Writer, r *http.Request) {
if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ERROR: parsing arguments: %v\n", err)
return
}
sinceTickStr := r.Form.Get("sincetick")
var tick int64
if sinceTickStr != "" {
var err error
if tick, err = strconv.ParseInt(sinceTickStr, 10, 64); err != nil {
fmt.Fprintf(w, "ERROR: parsing sincemilli: %v\n", err)
}
}
fmt.Fprintf(w, "SUCCESS\n")
// fmt.Fprintf(w, "%d,%d\n", p2p.ingressTrafficMeter, )
dataflow.HeaderDownloadStates.ChangesSince(int(tick), w)
}