Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions util/indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ckb-notify.workspace = true
ckb-async-runtime.workspace = true
ckb-indexer-sync.workspace = true
rocksdb = { workspace = true, features = ["snappy"], default-features = false }
ckb-metrics.workspace = true
memchr.workspace = true

[dev-dependencies]
Expand Down
16 changes: 16 additions & 0 deletions util/indexer/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ where
if block_number % self.prune_interval == 0 {
self.prune()?;
}

// Update indexer tip metric
if let Some(metrics) = ckb_metrics::handle() {
metrics.ckb_indexer_tip.set(block_number as i64);
}

Ok(())
}

Expand Down Expand Up @@ -672,6 +678,16 @@ where
batch.delete(Key::Header(block_number, &block_hash, filtered).into_vec())?;

batch.commit()?;

// Update indexer tip metric after rollback
if let Some(metrics) = ckb_metrics::handle() {
// After rollback, the new tip is block_number - 1
if block_number > 0 {
metrics.ckb_indexer_tip.set((block_number - 1) as i64);
} else {
metrics.ckb_indexer_tip.set(0);
}
}
}
Ok(())
}
Expand Down
7 changes: 7 additions & 0 deletions util/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ pub struct Metrics {
pub ckb_hole_punching_active_success_count: IntCounter,
pub ckb_hole_punching_passive_count: IntCounter,
pub ckb_hole_punching_passive_success_count: IntCounter,
/// Gauge metric for CKB indexer tip block number
pub ckb_indexer_tip: IntGauge,
}

static METRICS: std::sync::LazyLock<Metrics> = std::sync::LazyLock::new(|| {
Expand Down Expand Up @@ -336,6 +338,11 @@ static METRICS: std::sync::LazyLock<Metrics> = std::sync::LazyLock::new(|| {
"The CKB hole punching passive success count"
)
.unwrap(),
ckb_indexer_tip: register_int_gauge!(
"ckb_indexer_tip",
"The CKB indexer tip block number"
)
.unwrap(),
}
});

Expand Down
Loading