Renamed metrics and added implicit label `coin`
parent
b412b60c9c
commit
96a60bf7fa
|
@ -570,7 +570,7 @@ func (b *BitcoinRPC) observeRPCLatency(method string, fn func() error) error {
|
|||
start := time.Now()
|
||||
err := fn()
|
||||
if err == nil {
|
||||
b.metrics.BlockChainLatency.With(common.Labels{"coin": "bitcoin", "method": method}).Observe(float64(time.Since(start)) / 1e6) // in milliseconds
|
||||
b.metrics.RPCLatency.With(common.Labels{"method": method}).Observe(float64(time.Since(start)) / 1e6) // in milliseconds
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
metrics, err := common.GetMetrics()
|
||||
metrics, err := common.GetMetrics(*coin)
|
||||
if err != nil {
|
||||
glog.Fatal("GetMetrics: ", err)
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@ import (
|
|||
)
|
||||
|
||||
type Metrics struct {
|
||||
RPCRequests *prometheus.CounterVec
|
||||
SubscribeRequests *prometheus.CounterVec
|
||||
Clients *prometheus.GaugeVec
|
||||
RequestDuration *prometheus.HistogramVec
|
||||
SocketIORequests *prometheus.CounterVec
|
||||
SocketIOSubscribes *prometheus.CounterVec
|
||||
SocketIOClients prometheus.Gauge
|
||||
SocketIOReqDuration *prometheus.HistogramVec
|
||||
IndexResyncDuration prometheus.Histogram
|
||||
MempoolResyncDuration prometheus.Histogram
|
||||
TxCacheEfficiency *prometheus.CounterVec
|
||||
BlockChainLatency *prometheus.HistogramVec
|
||||
RPCLatency *prometheus.HistogramVec
|
||||
IndexResyncErrors *prometheus.CounterVec
|
||||
MempoolResyncErrors *prometheus.CounterVec
|
||||
IndexDBSize prometheus.Gauge
|
||||
|
@ -22,85 +22,95 @@ type Metrics struct {
|
|||
|
||||
type Labels = prometheus.Labels
|
||||
|
||||
func GetMetrics() (*Metrics, error) {
|
||||
func GetMetrics(coin string) (*Metrics, error) {
|
||||
metrics := Metrics{}
|
||||
|
||||
metrics.RPCRequests = prometheus.NewCounterVec(
|
||||
metrics.SocketIORequests = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "blockbook_rpc_requests",
|
||||
Help: "Total number of RPC requests by transport, method and status",
|
||||
Name: "blockbook_socketio_requests",
|
||||
Help: "Total number of socketio requests by method and status",
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
[]string{"transport", "method", "status"},
|
||||
[]string{"method", "status"},
|
||||
)
|
||||
metrics.SubscribeRequests = prometheus.NewCounterVec(
|
||||
metrics.SocketIOSubscribes = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "blockbook_subscribe_requests",
|
||||
Help: "Total number of subscribe requests by transport, channel and status",
|
||||
Name: "blockbook_socketio_subscribes",
|
||||
Help: "Total number of socketio subscribes by channel and status",
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
[]string{"transport", "channel", "status"},
|
||||
[]string{"channel", "status"},
|
||||
)
|
||||
metrics.Clients = prometheus.NewGaugeVec(
|
||||
metrics.SocketIOClients = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "blockbook_clients",
|
||||
Help: "Number of currently connected clients by transport",
|
||||
Name: "blockbook_socketio_clients",
|
||||
Help: "Number of currently connected clients",
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
[]string{"transport"},
|
||||
)
|
||||
metrics.RequestDuration = prometheus.NewHistogramVec(
|
||||
metrics.SocketIOReqDuration = prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Name: "blockbook_request_duration",
|
||||
Help: "Request duration by method (in microseconds)",
|
||||
Buckets: []float64{1, 5, 10, 25, 50, 75, 100, 250},
|
||||
Name: "blockbook_socketio_req_duration",
|
||||
Help: "Socketio request duration by method (in microseconds)",
|
||||
Buckets: []float64{1, 5, 10, 25, 50, 75, 100, 250},
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
[]string{"transport", "method"},
|
||||
[]string{"method"},
|
||||
)
|
||||
metrics.IndexResyncDuration = prometheus.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Name: "blockbook_index_resync_duration",
|
||||
Help: "Duration of index resync operation (in milliseconds)",
|
||||
Buckets: []float64{100, 250, 500, 750, 1000, 10000, 30000, 60000},
|
||||
Name: "blockbook_index_resync_duration",
|
||||
Help: "Duration of index resync operation (in milliseconds)",
|
||||
Buckets: []float64{100, 250, 500, 750, 1000, 10000, 30000, 60000},
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
)
|
||||
metrics.MempoolResyncDuration = prometheus.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Name: "blockbook_mempool_resync_duration",
|
||||
Help: "Duration of mempool resync operation (in milliseconds)",
|
||||
Buckets: []float64{1, 5, 10, 25, 50, 75, 100, 250},
|
||||
Name: "blockbook_mempool_resync_duration",
|
||||
Help: "Duration of mempool resync operation (in milliseconds)",
|
||||
Buckets: []float64{1, 5, 10, 25, 50, 75, 100, 250},
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
)
|
||||
metrics.TxCacheEfficiency = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "blockbook_txcache_efficiency",
|
||||
Help: "Efficiency of txCache",
|
||||
Name: "blockbook_txcache_efficiency",
|
||||
Help: "Efficiency of txCache",
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
[]string{"status"},
|
||||
)
|
||||
metrics.BlockChainLatency = prometheus.NewHistogramVec(
|
||||
metrics.RPCLatency = prometheus.NewHistogramVec(
|
||||
prometheus.HistogramOpts{
|
||||
Name: "blockbook_blockchain_latency",
|
||||
Help: "Latency of blockchain RPC by coin and method (in milliseconds)",
|
||||
Buckets: []float64{1, 5, 10, 25, 50, 75, 100, 250},
|
||||
Name: "blockbook_rpc_latency",
|
||||
Help: "Latency of blockchain RPC by method (in milliseconds)",
|
||||
Buckets: []float64{1, 5, 10, 25, 50, 75, 100, 250},
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
[]string{"coin", "method"},
|
||||
[]string{"method"},
|
||||
)
|
||||
metrics.IndexResyncErrors = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "blockbook_index_resync_errors",
|
||||
Help: "Number of errors of index resync operation",
|
||||
Name: "blockbook_index_resync_errors",
|
||||
Help: "Number of errors of index resync operation",
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
[]string{"error"},
|
||||
)
|
||||
metrics.MempoolResyncErrors = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Name: "blockbook_mempool_resync_errors",
|
||||
Help: "Number of errors of mempool resync operation",
|
||||
Name: "blockbook_mempool_resync_errors",
|
||||
Help: "Number of errors of mempool resync operation",
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
[]string{"error"},
|
||||
)
|
||||
metrics.IndexDBSize = prometheus.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "blockbook_index_db_size",
|
||||
Help: "Size of index database (in bytes)",
|
||||
Name: "blockbook_index_db_size",
|
||||
Help: "Size of index database (in bytes)",
|
||||
ConstLabels: Labels{"coin": coin},
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -38,12 +38,12 @@ func NewSocketIoServer(binding string, certFiles string, db *db.RocksDB, chain b
|
|||
|
||||
server.On(gosocketio.OnConnection, func(c *gosocketio.Channel) {
|
||||
glog.Info("Client connected ", c.Id())
|
||||
metrics.Clients.With(common.Labels{"transport": "socketio"}).Inc()
|
||||
metrics.SocketIOClients.Inc()
|
||||
})
|
||||
|
||||
server.On(gosocketio.OnDisconnection, func(c *gosocketio.Channel) {
|
||||
glog.Info("Client disconnected ", c.Id())
|
||||
metrics.Clients.With(common.Labels{"transport": "socketio"}).Dec()
|
||||
metrics.SocketIOClients.Dec()
|
||||
})
|
||||
|
||||
server.On(gosocketio.OnError, func(c *gosocketio.Channel) {
|
||||
|
@ -200,7 +200,7 @@ func (s *SocketIoServer) onMessage(c *gosocketio.Channel, req map[string]json.Ra
|
|||
t := time.Now()
|
||||
method := strings.Trim(string(req["method"]), "\"")
|
||||
params := req["params"]
|
||||
defer s.metrics.RequestDuration.With(common.Labels{"transport": "socketio", "method": method}).Observe(float64(time.Since(t)) / 1e3) // in microseconds
|
||||
defer s.metrics.SocketIOReqDuration.With(common.Labels{"method": method}).Observe(float64(time.Since(t)) / 1e3) // in microseconds
|
||||
f, ok := onMessageHandlers[method]
|
||||
if ok {
|
||||
rv, err = f(s, params)
|
||||
|
@ -209,11 +209,11 @@ func (s *SocketIoServer) onMessage(c *gosocketio.Channel, req map[string]json.Ra
|
|||
}
|
||||
if err == nil {
|
||||
glog.V(1).Info(c.Id(), " onMessage ", method, " success")
|
||||
s.metrics.RPCRequests.With(common.Labels{"transport": "socketio", "method": method, "status": "success"}).Inc()
|
||||
s.metrics.SocketIORequests.With(common.Labels{"method": method, "status": "success"}).Inc()
|
||||
return rv
|
||||
}
|
||||
glog.Error(c.Id(), " onMessage ", method, ": ", errors.ErrorStack(err))
|
||||
s.metrics.RPCRequests.With(common.Labels{"transport": "socketio", "method": method, "status": err.Error()}).Inc()
|
||||
s.metrics.SocketIORequests.With(common.Labels{"method": method, "status": err.Error()}).Inc()
|
||||
e := resultError{}
|
||||
e.Error.Message = err.Error()
|
||||
return e
|
||||
|
@ -662,7 +662,7 @@ func (s *SocketIoServer) getMempoolEntry(txid string) (res resultGetMempoolEntry
|
|||
func (s *SocketIoServer) onSubscribe(c *gosocketio.Channel, req []byte) interface{} {
|
||||
onError := func(id, sc, err string) {
|
||||
glog.Error(id, " onSubscribe ", sc, ": ", err)
|
||||
s.metrics.SubscribeRequests.With(common.Labels{"transport": "socketio", "channel": sc, "status": err}).Inc()
|
||||
s.metrics.SocketIOSubscribes.With(common.Labels{"channel": sc, "status": err}).Inc()
|
||||
}
|
||||
|
||||
r := string(req)
|
||||
|
@ -692,7 +692,7 @@ func (s *SocketIoServer) onSubscribe(c *gosocketio.Channel, req []byte) interfac
|
|||
}
|
||||
c.Join(sc)
|
||||
}
|
||||
s.metrics.SubscribeRequests.With(common.Labels{"transport": "socketio", "channel": sc, "status": "success"}).Inc()
|
||||
s.metrics.SocketIOSubscribes.With(common.Labels{"channel": sc, "status": "success"}).Inc()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue