Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tx-submitter/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Metrics struct {
FinalizeCost prometheus.Gauge
CollectedL1FeeSum prometheus.Gauge
IndexerBlockProcessed prometheus.Gauge
LastCommittedBatch prometheus.Gauge
LastFinalizedBatch prometheus.Gauge
reorgs prometheus.Counter
reorgDepthVal uint64
reorgCountVal uint64
Expand Down Expand Up @@ -61,6 +63,14 @@ func NewMetrics() *Metrics {
Name: "tx_submitter_indexer_block_processed",
Help: "Latest block number processed by the indexer",
}),
LastCommittedBatch: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "tx_submitter_last_committed_batch",
Help: "Latest batch committed by the submitter",
}),
LastFinalizedBatch: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "tx_submitter_last_finalized_batch",
Help: "Latest batch finalized by the submitter",
}),
reorgs: prometheus.NewCounter(prometheus.CounterOpts{
Name: "tx_submitter_reorgs_total",
Help: "Total number of chain reorganizations detected",
Expand All @@ -74,6 +84,21 @@ func NewMetrics() *Metrics {
),
}

// Register metrics with Prometheus
// We use Register instead of MustRegister to avoid panics if metrics are already registered
_ = prometheus.Register(m.WalletBalance)
_ = prometheus.Register(m.RpcErrors)
_ = prometheus.Register(m.RollupCostSum)
_ = prometheus.Register(m.FinalizeCostSum)
_ = prometheus.Register(m.RollupCost)
_ = prometheus.Register(m.FinalizeCost)
_ = prometheus.Register(m.CollectedL1FeeSum)
_ = prometheus.Register(m.IndexerBlockProcessed)
_ = prometheus.Register(m.LastCommittedBatch)
_ = prometheus.Register(m.LastFinalizedBatch)
_ = prometheus.Register(m.reorgs)
_ = prometheus.Register(m.confirmedTxs)

return m
}

Expand Down Expand Up @@ -109,6 +134,16 @@ func (m *Metrics) SetIndexerBlockProcessed(blockNumber uint64) {
m.IndexerBlockProcessed.Set(float64(blockNumber))
}

// SetLastCommittedBatch sets the last committed batch index metric
func (m *Metrics) SetLastCommittedBatch(index uint64) {
m.LastCommittedBatch.Set(float64(index))
}

// SetLastFinalizedBatch sets the last finalized batch index metric
func (m *Metrics) SetLastFinalizedBatch(index uint64) {
m.LastFinalizedBatch.Set(float64(index))
}

// IncReorgs increments the reorg counter
func (m *Metrics) IncReorgs() {
atomic.AddUint64(&m.reorgCountVal, 1)
Expand Down Expand Up @@ -155,6 +190,8 @@ func (m *Metrics) UnregisterMetrics() {
prometheus.Unregister(m.FinalizeCost)
prometheus.Unregister(m.CollectedL1FeeSum)
prometheus.Unregister(m.IndexerBlockProcessed)
prometheus.Unregister(m.LastCommittedBatch)
prometheus.Unregister(m.LastFinalizedBatch)
prometheus.Unregister(m.reorgs)
prometheus.Unregister(m.confirmedTxs)
}
16 changes: 14 additions & 2 deletions tx-submitter/services/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func (r *Rollup) Start() error {

// metrics
go utils.Loop(r.ctx, 10*time.Second, func() {

// get balacnce of wallet
balance, err := r.L1Client.BalanceAt(context.Background(), r.WalletAddr(), nil)
if err != nil {
Expand All @@ -184,8 +183,21 @@ func (r *Rollup) Start() error {
log.Warn("parse balance to float error", "error", err)
return
}

r.metrics.SetWalletBalance(balanceEthFloat)
// last committed batch
lastCommittedBatch, err := r.Rollup.LastCommittedBatchIndex(nil)
if err != nil {
log.Warn("get last committed batch error", "error", err)
return
}
r.metrics.SetLastCommittedBatch(lastCommittedBatch.Uint64())
// last finalized batch
lastFinalizedBatch, err := r.Rollup.LastFinalizedBatchIndex(nil)
if err != nil {
log.Warn("get last finalized batch error", "error", err)
return
}
r.metrics.SetLastFinalizedBatch(lastFinalizedBatch.Uint64())

})

Expand Down
Loading