diff --git a/tx-submitter/metrics/metrics.go b/tx-submitter/metrics/metrics.go index 1f153c85f..0e3b83f01 100644 --- a/tx-submitter/metrics/metrics.go +++ b/tx-submitter/metrics/metrics.go @@ -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 @@ -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", @@ -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 } @@ -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) @@ -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) } diff --git a/tx-submitter/services/rollup.go b/tx-submitter/services/rollup.go index 08e6395fa..56cbd43ce 100644 --- a/tx-submitter/services/rollup.go +++ b/tx-submitter/services/rollup.go @@ -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 { @@ -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()) })