diff --git a/common/metrics.go b/common/metrics.go index 51b5f970..b37cafac 100644 --- a/common/metrics.go +++ b/common/metrics.go @@ -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) diff --git a/server/socketio.go b/server/socketio.go index 3ea084d4..a45530be 100644 --- a/server/socketio.go +++ b/server/socketio.go @@ -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() } }