Skip to content

Commit

Permalink
Report mempool size in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboehm committed Jun 1, 2018
1 parent 17ed8f7 commit eba668b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bchain/coins/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ func (c *blockChainWithMetrics) SendRawTransaction(tx string) (v string, err err

func (c *blockChainWithMetrics) ResyncMempool(onNewTxAddr func(txid string, addr string)) (count int, err error) {
defer func(s time.Time) { c.observeRPCLatency("ResyncMempool", s, err) }(time.Now())
return c.b.ResyncMempool(onNewTxAddr)
count, err = c.b.ResyncMempool(onNewTxAddr)
if err == nil {
c.m.MempoolSize.Set(float64(count))
}
return count, err
}

func (c *blockChainWithMetrics) GetMempoolTransactions(address string) (v []string, err error) {
Expand Down
8 changes: 8 additions & 0 deletions common/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Metrics struct {
IndexResyncErrors *prometheus.CounterVec
IndexDBSize prometheus.Gauge
ExplorerViews *prometheus.CounterVec
MempoolSize prometheus.Gauge
}

type Labels = prometheus.Labels
Expand Down Expand Up @@ -113,6 +114,13 @@ func GetMetrics(coin string) (*Metrics, error) {
},
[]string{"action"},
)
metrics.MempoolSize = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "blockbook_mempool_size",
Help: "Mempool size (number of transactions)",
ConstLabels: Labels{"coin": coin},
},
)

v := reflect.ValueOf(metrics)
for i := 0; i < v.NumField(); i++ {
Expand Down

0 comments on commit eba668b

Please sign in to comment.