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