Skip to content

Commit

Permalink
add txpool_size metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawliet-Chan committed Sep 20, 2024
1 parent b362465 commit 35c8e38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion core/txpool/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
)

type ItxPool interface {
// Capacity return pool Size of txpool
// Capacity return pool capacity of txpool
Capacity() int
// Size return pool size of txpool
Size() int

WithBaseCheck(checkFn TxnChecker) ItxPool
Expand Down
2 changes: 2 additions & 0 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
. "github.com/yu-org/yu/common/yerror"
. "github.com/yu-org/yu/config"
. "github.com/yu-org/yu/core/types"
"github.com/yu-org/yu/metrics"
)

type TxPool struct {
Expand Down Expand Up @@ -123,6 +124,7 @@ func (tp *TxPool) Pack(numLimit uint64) ([]*SignedTxn, error) {
func (tp *TxPool) PackFor(numLimit uint64, filter func(txn *SignedTxn) bool) ([]*SignedTxn, error) {
//tp.RLock()
//defer tp.RUnlock()
metrics.TxpoolSizeGauge.Set(float64(tp.unpackedTxns.Size()))
txns := tp.unpackedTxns.Gets(numLimit, filter)
return txns, nil
}
Expand Down
24 changes: 11 additions & 13 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ import (
)

var (
BlockNumLabel = "block_num"
TripodLabel = "tripod"
TripodLabel = "tripod"
)

var (
TxsPackCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
TxpoolSizeGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "yu",
Subsystem: "transaction",
Name: "txs_pack",
Help: "Total number of count of packing txn",
Subsystem: "txpool",
Name: "txpool_size",
Help: "Total number of txpool",
},
[]string{BlockNumLabel},
)

StartBlockDuration = prometheus.NewHistogramVec(
Expand All @@ -27,7 +25,7 @@ var (
Name: "start_block",
Help: "Start Block duration",
},
[]string{BlockNumLabel, TripodLabel},
[]string{TripodLabel},
)

EndBlockDuration = prometheus.NewHistogramVec(
Expand All @@ -37,7 +35,7 @@ var (
Name: "end_block",
Help: "End Block duration",
},
[]string{BlockNumLabel, TripodLabel},
[]string{TripodLabel},
)

FinalizeBlockDuration = prometheus.NewHistogramVec(
Expand All @@ -47,7 +45,7 @@ var (
Name: "finalize_block",
Help: "Finalize Block duration",
},
[]string{BlockNumLabel, TripodLabel},
[]string{TripodLabel},
)

AppendBlockDuration = prometheus.NewHistogramVec(
Expand All @@ -57,7 +55,7 @@ var (
Name: "append_block",
Help: "append block duration",
},
[]string{BlockNumLabel},
[]string{},
)

StateCommitDuration = prometheus.NewHistogramVec(
Expand All @@ -72,7 +70,7 @@ var (
)

func init() {
prometheus.MustRegister(TxsPackCounter)
prometheus.MustRegister(TxpoolSizeGauge)
// prometheus.MustRegister(AppendBlockDuration, StartBlockDuration, EndBlockDuration, FinalizeBlockDuration)
prometheus.MustRegister(StateCommitDuration)
}

0 comments on commit 35c8e38

Please sign in to comment.