2023-05-29 07:18:31 +00:00
|
|
|
package diagnostics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon/dataflow"
|
|
|
|
)
|
|
|
|
|
2023-08-31 08:04:27 +00:00
|
|
|
func SetupHeaderDownloadStats(metricsMux *http.ServeMux) {
|
2023-09-25 15:24:17 +00:00
|
|
|
metricsMux.HandleFunc("/headers_download", func(w http.ResponseWriter, r *http.Request) {
|
2023-05-29 07:18:31 +00:00
|
|
|
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)
|
|
|
|
}
|