Add params serving
This commit is contained in:
parent
b1d587b504
commit
b13f65a9ab
|
@ -47,6 +47,8 @@ func init() {
|
||||||
promRegistry.MustRegister(metrics.TotalErrors)
|
promRegistry.MustRegister(metrics.TotalErrors)
|
||||||
promRegistry.MustRegister(metrics.TotalBlocksServedConter)
|
promRegistry.MustRegister(metrics.TotalBlocksServedConter)
|
||||||
promRegistry.MustRegister(metrics.SendTransactionsCounter)
|
promRegistry.MustRegister(metrics.SendTransactionsCounter)
|
||||||
|
promRegistry.MustRegister(metrics.TotalSaplingParamsCounter)
|
||||||
|
promRegistry.MustRegister(metrics.TotalSproutParamsCounter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO stream logging
|
// TODO stream logging
|
||||||
|
@ -255,6 +257,10 @@ func main() {
|
||||||
log.Fatal(http.ListenAndServe(":2234", nil))
|
log.Fatal(http.ListenAndServe(":2234", nil))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Start the download params handler
|
||||||
|
log.Infof("Starting params handler")
|
||||||
|
go common.ParamsDownloadHandler(metrics)
|
||||||
|
|
||||||
log.Infof("Starting gRPC server on %s", opts.bindAddr)
|
log.Infof("Starting gRPC server on %s", opts.bindAddr)
|
||||||
|
|
||||||
err = server.Serve(listener)
|
err = server.Serve(listener)
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
metrics *PrometheusMetrics
|
||||||
|
)
|
||||||
|
|
||||||
|
// Handle http(s) downloads for zcash params
|
||||||
|
func paramsHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
if strings.HasSuffix(req.URL.Path, "sapling-output.params") {
|
||||||
|
metrics.TotalSaplingParamsCounter.Inc()
|
||||||
|
http.Redirect(w, req, "https://z.cash/downloads/sapling-output.params", 301)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(req.URL.Path, "sapling-spend.params") {
|
||||||
|
http.Redirect(w, req, "https://z.cash/downloads/sapling-spend.params", 301)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(req.URL.Path, "sprout-groth16.params") {
|
||||||
|
metrics.TotalSproutParamsCounter.Inc()
|
||||||
|
http.Redirect(w, req, "https://z.cash/downloads/sprout-groth16.params", 301)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Error(w, "Not Found", 404)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParamsDownloadHandler Listens on port 8090 for download requests for params
|
||||||
|
func ParamsDownloadHandler(prommetrics *PrometheusMetrics) {
|
||||||
|
metrics = prommetrics
|
||||||
|
http.HandleFunc("/params/", paramsHandler)
|
||||||
|
|
||||||
|
println("Handling at params")
|
||||||
|
http.ListenAndServe(":8090", nil)
|
||||||
|
}
|
|
@ -8,6 +8,8 @@ type PrometheusMetrics struct {
|
||||||
TotalBlocksServedConter prometheus.Counter
|
TotalBlocksServedConter prometheus.Counter
|
||||||
SendTransactionsCounter prometheus.Counter
|
SendTransactionsCounter prometheus.Counter
|
||||||
TotalErrors prometheus.Counter
|
TotalErrors prometheus.Counter
|
||||||
|
TotalSaplingParamsCounter prometheus.Counter
|
||||||
|
TotalSproutParamsCounter prometheus.Counter
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPrometheusMetrics() *PrometheusMetrics {
|
func GetPrometheusMetrics() *PrometheusMetrics {
|
||||||
|
@ -32,5 +34,15 @@ func GetPrometheusMetrics() *PrometheusMetrics {
|
||||||
Help: "Total number of errors seen by lightwalletd",
|
Help: "Total number of errors seen by lightwalletd",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
m.TotalSaplingParamsCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Name: "params_sapling_total",
|
||||||
|
Help: "Total number of params downloads for sapling params",
|
||||||
|
})
|
||||||
|
|
||||||
|
m.TotalSproutParamsCounter = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Name: "params_sprout_total",
|
||||||
|
Help: "Total number of params downloasd for sprout params",
|
||||||
|
})
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue