Handle redirect blockchain explorer for address request

pull/7/head
Martin Boehm 2018-05-28 10:19:30 +02:00
parent 038065429f
commit 0467e11d59
2 changed files with 14 additions and 6 deletions

View File

@ -17,7 +17,7 @@ type Metrics struct {
RPCLatency *prometheus.HistogramVec
IndexResyncErrors *prometheus.CounterVec
IndexDBSize prometheus.Gauge
TxExplorerRedirects *prometheus.CounterVec
ExplorerViews *prometheus.CounterVec
}
type Labels = prometheus.Labels
@ -105,13 +105,13 @@ func GetMetrics(coin string) (*Metrics, error) {
ConstLabels: Labels{"coin": coin},
},
)
metrics.TxExplorerRedirects = prometheus.NewCounterVec(
metrics.ExplorerViews = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "blockbook_tx_explorer_views",
Help: "Number of views of the transaction explorer",
Name: "blockbook_explorer_views",
Help: "Number of explorer views",
ConstLabels: Labels{"coin": coin},
},
[]string{},
[]string{"action"},
)
v := reflect.ValueOf(metrics)

View File

@ -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/")))
// redirect to Bitcore for details of transaction
serveMux.HandleFunc(path+"tx/", s.txRedirect)
serveMux.HandleFunc(path+"address/", s.addressRedirect)
// API call used to detect state of Blockbook
serveMux.HandleFunc(path+"api/block-index/", s.apiBlockIndex)
// 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) {
if s.explorerURL != "" {
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()
}
}