Handle redirect blockchain explorer for address request
This commit is contained in:
parent
038065429f
commit
0467e11d59
@ -17,7 +17,7 @@ type Metrics struct {
|
|||||||
RPCLatency *prometheus.HistogramVec
|
RPCLatency *prometheus.HistogramVec
|
||||||
IndexResyncErrors *prometheus.CounterVec
|
IndexResyncErrors *prometheus.CounterVec
|
||||||
IndexDBSize prometheus.Gauge
|
IndexDBSize prometheus.Gauge
|
||||||
TxExplorerRedirects *prometheus.CounterVec
|
ExplorerViews *prometheus.CounterVec
|
||||||
}
|
}
|
||||||
|
|
||||||
type Labels = prometheus.Labels
|
type Labels = prometheus.Labels
|
||||||
@ -105,13 +105,13 @@ func GetMetrics(coin string) (*Metrics, error) {
|
|||||||
ConstLabels: Labels{"coin": coin},
|
ConstLabels: Labels{"coin": coin},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
metrics.TxExplorerRedirects = prometheus.NewCounterVec(
|
metrics.ExplorerViews = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Name: "blockbook_tx_explorer_views",
|
Name: "blockbook_explorer_views",
|
||||||
Help: "Number of views of the transaction explorer",
|
Help: "Number of explorer views",
|
||||||
ConstLabels: Labels{"coin": coin},
|
ConstLabels: Labels{"coin": coin},
|
||||||
},
|
},
|
||||||
[]string{},
|
[]string{"action"},
|
||||||
)
|
)
|
||||||
|
|
||||||
v := reflect.ValueOf(metrics)
|
v := reflect.ValueOf(metrics)
|
||||||
|
|||||||
@ -82,6 +82,7 @@ func NewSocketIoServer(binding string, certFiles string, db *db.RocksDB, chain b
|
|||||||
serveMux.Handle(path+"test.html", http.FileServer(http.Dir("./static/")))
|
serveMux.Handle(path+"test.html", http.FileServer(http.Dir("./static/")))
|
||||||
// redirect to Bitcore for details of transaction
|
// redirect to Bitcore for details of transaction
|
||||||
serveMux.HandleFunc(path+"tx/", s.txRedirect)
|
serveMux.HandleFunc(path+"tx/", s.txRedirect)
|
||||||
|
serveMux.HandleFunc(path+"address/", s.addressRedirect)
|
||||||
// API call used to detect state of Blockbook
|
// API call used to detect state of Blockbook
|
||||||
serveMux.HandleFunc(path+"api/block-index/", s.apiBlockIndex)
|
serveMux.HandleFunc(path+"api/block-index/", s.apiBlockIndex)
|
||||||
// handle socket.io
|
// handle socket.io
|
||||||
@ -128,7 +129,14 @@ func (s *SocketIoServer) Shutdown(ctx context.Context) error {
|
|||||||
func (s *SocketIoServer) txRedirect(w http.ResponseWriter, r *http.Request) {
|
func (s *SocketIoServer) txRedirect(w http.ResponseWriter, r *http.Request) {
|
||||||
if s.explorerURL != "" {
|
if s.explorerURL != "" {
|
||||||
http.Redirect(w, r, s.explorerURL+r.URL.Path, 302)
|
http.Redirect(w, r, s.explorerURL+r.URL.Path, 302)
|
||||||
s.metrics.TxExplorerRedirects.With(common.Labels{}).Inc()
|
s.metrics.ExplorerViews.With(common.Labels{"action": "tx"}).Inc()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SocketIoServer) addressRedirect(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if s.explorerURL != "" {
|
||||||
|
http.Redirect(w, r, s.explorerURL+r.URL.Path, 302)
|
||||||
|
s.metrics.ExplorerViews.With(common.Labels{"action": "address"}).Inc()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user