Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
add metrics that have counters for the size of the txs that have arri…
Browse files Browse the repository at this point in the history
…ved vs the txs (#166)

Co-authored-by: nhutton <[email protected]>
  • Loading branch information
n-hutton and nhutton authored Aug 17, 2020
1 parent 523f4f4 commit 2aeca6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ func (mem *CListMempool) TxsWaitChan() <-chan struct{} {
// It gets called from another goroutine.
// CONTRACT: Either cb will get called, or err returned.
func (mem *CListMempool) CheckTx(tx types.Tx, cb func(*abci.Response), txInfo TxInfo) (err error) {

mem.metrics.TxsArrived.Add(1.0)

mem.proxyMtx.Lock()
// use defer to unlock mutex because application (*local client*) might panic
defer mem.proxyMtx.Unlock()
Expand Down Expand Up @@ -366,6 +369,9 @@ func isPriority(tx types.Tx) bool {
// Called from:
// - ResCbFirstTime (lock not held) if tx is valid
func (mem *CListMempool) addTx(memTx *mempoolTx) {

mem.metrics.TxsVerified.Add(1.0)

if isPriority(memTx.tx) {
e := mem.txs.PushFront(memTx)
mem.txsMap.Store(txKey(memTx.tx), e)
Expand Down
18 changes: 18 additions & 0 deletions mempool/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type Metrics struct {
GasReap metrics.Gauge
// Percentage of the mempool reaped by transaction
MempoolReapedPercent metrics.Gauge
// Number of Txs that have arrived in the mempool
TxsArrived metrics.Gauge
// Number of Txs that have been verified in the mempool
TxsVerified metrics.Gauge
}

// PrometheusMetrics returns Metrics build using Prometheus client library.
Expand Down Expand Up @@ -100,6 +104,18 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
Name: "mempool_reaped_percent",
Help: "Percent of the mempool reaped for block creation",
}, labels).With(labelsAndValues...),
TxsArrived: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "txs_arrived",
Help: "Number of txs that have arrived in the mempool",
}, labels).With(labelsAndValues...),
TxsVerified: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "txs_verified",
Help: "Number of txs that have been verified in the mempool",
}, labels).With(labelsAndValues...),
}
}

Expand All @@ -115,5 +131,7 @@ func NopMetrics() *Metrics {
MaxGasReap: discard.NewGauge(),
GasReap: discard.NewGauge(),
MempoolReapedPercent: discard.NewGauge(),
TxsArrived: discard.NewGauge(),
TxsVerified: discard.NewGauge(),
}
}

0 comments on commit 2aeca6f

Please sign in to comment.