diff --git a/bchain/coins/blockchain.go b/bchain/coins/blockchain.go index d1d1a530..5ab95436 100644 --- a/bchain/coins/blockchain.go +++ b/bchain/coins/blockchain.go @@ -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) { diff --git a/common/metrics.go b/common/metrics.go index 0b2c0287..52376fef 100644 --- a/common/metrics.go +++ b/common/metrics.go @@ -18,6 +18,7 @@ type Metrics struct { IndexResyncErrors *prometheus.CounterVec IndexDBSize prometheus.Gauge ExplorerViews *prometheus.CounterVec + MempoolSize prometheus.Gauge } type Labels = prometheus.Labels @@ -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++ {