Add websocket subscription metrics
This commit is contained in:
parent
1482b51503
commit
8fd8e17929
@ -13,7 +13,7 @@ type Metrics struct {
|
||||
SocketIOClients prometheus.Gauge
|
||||
SocketIOReqDuration *prometheus.HistogramVec
|
||||
WebsocketRequests *prometheus.CounterVec
|
||||
WebsocketSubscribes *prometheus.CounterVec
|
||||
WebsocketSubscribes *prometheus.GaugeVec
|
||||
WebsocketClients prometheus.Gauge
|
||||
WebsocketReqDuration *prometheus.HistogramVec
|
||||
IndexResyncDuration prometheus.Histogram
|
||||
@ -82,13 +82,13 @@ func GetMetrics(coin string) (*Metrics, error) {
|
||||
},
|
||||
[]string{"method", "status"},
|
||||
)
|
||||
metrics.WebsocketSubscribes = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
metrics.WebsocketSubscribes = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "blockbook_websocket_subscribes",
|
||||
Help: "Total number of websocket subscribes by channel and status",
|
||||
Help: "Number of websocket subscriptions by method",
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
[]string{"channel", "status"},
|
||||
[]string{"method"},
|
||||
)
|
||||
metrics.WebsocketClients = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
|
||||
@ -688,6 +688,7 @@ func (s *WebsocketServer) subscribeNewBlock(c *websocketChannel, req *websocketR
|
||||
s.newBlockSubscriptionsLock.Lock()
|
||||
defer s.newBlockSubscriptionsLock.Unlock()
|
||||
s.newBlockSubscriptions[c] = req.ID
|
||||
s.metrics.WebsocketSubscribes.With((common.Labels{"method": "subscribeNewBlock"})).Set(float64(len(s.newBlockSubscriptions)))
|
||||
return &subscriptionResponse{true}, nil
|
||||
}
|
||||
|
||||
@ -695,6 +696,7 @@ func (s *WebsocketServer) unsubscribeNewBlock(c *websocketChannel) (res interfac
|
||||
s.newBlockSubscriptionsLock.Lock()
|
||||
defer s.newBlockSubscriptionsLock.Unlock()
|
||||
delete(s.newBlockSubscriptions, c)
|
||||
s.metrics.WebsocketSubscribes.With((common.Labels{"method": "subscribeNewBlock"})).Set(float64(len(s.newBlockSubscriptions)))
|
||||
return &subscriptionResponse{false}, nil
|
||||
}
|
||||
|
||||
@ -705,6 +707,7 @@ func (s *WebsocketServer) subscribeNewTransaction(c *websocketChannel, req *webs
|
||||
return &subscriptionResponseMessage{false, "subscribeNewTransaction not enabled, use -enablesubnewtx flag to enable."}, nil
|
||||
}
|
||||
s.newTransactionSubscriptions[c] = req.ID
|
||||
s.metrics.WebsocketSubscribes.With((common.Labels{"method": "subscribeNewTransaction"})).Set(float64(len(s.newTransactionSubscriptions)))
|
||||
return &subscriptionResponse{true}, nil
|
||||
}
|
||||
|
||||
@ -715,6 +718,7 @@ func (s *WebsocketServer) unsubscribeNewTransaction(c *websocketChannel) (res in
|
||||
return &subscriptionResponseMessage{false, "unsubscribeNewTransaction not enabled, use -enablesubnewtx flag to enable."}, nil
|
||||
}
|
||||
delete(s.newTransactionSubscriptions, c)
|
||||
s.metrics.WebsocketSubscribes.With((common.Labels{"method": "subscribeNewTransaction"})).Set(float64(len(s.newTransactionSubscriptions)))
|
||||
return &subscriptionResponse{false}, nil
|
||||
}
|
||||
|
||||
@ -765,6 +769,7 @@ func (s *WebsocketServer) subscribeAddresses(c *websocketChannel, addrDesc []bch
|
||||
}
|
||||
as[c] = req.ID
|
||||
}
|
||||
s.metrics.WebsocketSubscribes.With((common.Labels{"method": "subscribeAddresses"})).Set(float64(len(s.addressSubscriptions)))
|
||||
return &subscriptionResponse{true}, nil
|
||||
}
|
||||
|
||||
@ -773,6 +778,7 @@ func (s *WebsocketServer) unsubscribeAddresses(c *websocketChannel) (res interfa
|
||||
s.addressSubscriptionsLock.Lock()
|
||||
defer s.addressSubscriptionsLock.Unlock()
|
||||
s.doUnsubscribeAddresses(c)
|
||||
s.metrics.WebsocketSubscribes.With((common.Labels{"method": "subscribeAddresses"})).Set(float64(len(s.addressSubscriptions)))
|
||||
return &subscriptionResponse{false}, nil
|
||||
}
|
||||
|
||||
@ -805,6 +811,7 @@ func (s *WebsocketServer) subscribeFiatRates(c *websocketChannel, currency strin
|
||||
s.fiatRatesSubscriptions[currency] = as
|
||||
}
|
||||
as[c] = req.ID
|
||||
s.metrics.WebsocketSubscribes.With((common.Labels{"method": "subscribeFiatRates"})).Set(float64(len(s.fiatRatesSubscriptions)))
|
||||
return &subscriptionResponse{true}, nil
|
||||
}
|
||||
|
||||
@ -813,6 +820,7 @@ func (s *WebsocketServer) unsubscribeFiatRates(c *websocketChannel) (res interfa
|
||||
s.fiatRatesSubscriptionsLock.Lock()
|
||||
defer s.fiatRatesSubscriptionsLock.Unlock()
|
||||
s.doUnsubscribeFiatRates(c)
|
||||
s.metrics.WebsocketSubscribes.With((common.Labels{"method": "subscribeFiatRates"})).Set(float64(len(s.fiatRatesSubscriptions)))
|
||||
return &subscriptionResponse{false}, nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user