Skip to content

Commit

Permalink
add tx-pool metrics data
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Sep 19, 2023
1 parent fc3a440 commit 5e6e709
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
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.

7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ clippy: setup-ckb-test ## Run linter to examine Rust source codes.
cargo clippy ${VERBOSE} --all --all-targets --features ${ALL_FEATURES} -- ${CLIPPY_OPTS} -D missing_docs
cd test && cargo clippy ${VERBOSE} --all --all-targets --all-features -- ${CLIPPY_OPTS}

.PHONY: bless
bless: setup-ckb-test
cargo clippy --fix --allow-dirty ${VERBOSE} --all --all-targets --features ${ALL_FEATURES} -- ${CLIPPY_OPTS} -D missing_docs
cd test && cargo clippy --fix --allow-dirty ${VERBOSE} --all --all-targets --all-features -- ${CLIPPY_OPTS}
cargo fmt ${VERBOSE} --all
cd test && cargo fmt ${VERBOSE} --all

.PHONY: security-audit
security-audit: ## Use cargo-deny to audit Cargo.lock for crates with security vulnerabilities.
cargo deny check --hide-inclusion-graph --show-stats advisories sources
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct RpcTestSuite {

impl RpcTestSuite {
fn rpc(&self, request: &RpcTestRequest) -> RpcTestResponse {
self.rpc_client
self.rpc_client
.post(&self.rpc_uri)
.json(&request)
.send()
Expand Down
1 change: 1 addition & 0 deletions tx-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ckb-util = { path = "../util", version = "= 0.112.0-pre" }
ckb-jsonrpc-types = { path = "../util/jsonrpc-types", version = "= 0.112.0-pre" }
ckb-chain-spec = { path = "../spec", version = "= 0.112.0-pre" }
ckb-snapshot = { path = "../util/snapshot", version = "= 0.112.0-pre" }
ckb-metrics = {path = "../util/metrics", version = "= 0.112.0-pre"}
ckb-error = { path = "../error", version = "= 0.112.0-pre" }
tokio = { version = "1", features = ["sync", "process"] }
ckb-async-runtime = { path = "../util/runtime", version = "= 0.112.0-pre" }
Expand Down
19 changes: 19 additions & 0 deletions tx-pool/src/component/pool_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl PoolMap {
self.insert_entry(&entry, status);
self.record_entry_edges(&entry);
self.record_entry_descendants(&entry);
self.track_entry_statics();
Ok(true)
}

Expand All @@ -193,6 +194,7 @@ impl PoolMap {
e.status = status;
})
.expect("unconsistent pool");
self.track_entry_statics();
}

pub(crate) fn remove_entry(&mut self, id: &ProposalShortId) -> Option<TxEntry> {
Expand Down Expand Up @@ -504,4 +506,21 @@ impl PoolMap {
evict_key,
});
}

fn track_entry_statics(&self) {
if let Some(metrics) = ckb_metrics::handle() {
metrics
.ckb_tx_pool_entry
.pending
.set(self.entries.get_by_status(&Status::Pending).len() as i64);
metrics
.ckb_tx_pool_entry
.gap
.set(self.entries.get_by_status(&Status::Gap).len() as i64);
metrics
.ckb_tx_pool_entry
.proposed
.set(self.proposed_size() as i64);
}
}
}
19 changes: 19 additions & 0 deletions util/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ make_static_metric! {
metadata,
},
}

// Struct for CKB tx-pool entry status statistics type label
struct CkbTxPoolEntryStatistics: IntGauge{
"type" => {
pending,
gap,
proposed,
},
}
}

pub struct Metrics {
Expand Down Expand Up @@ -64,6 +73,8 @@ pub struct Metrics {
pub ckb_sys_mem_process: CkbSysMemProcessStatistics,
// GaugeVec for CKB system memory jemalloc statistics
pub ckb_sys_mem_jemalloc: CkbSysMemJemallocStatistics,
// GaugeVec for CKB tx-pool tx entry status statistics
pub ckb_tx_pool_entry: CkbTxPoolEntryStatistics,
/// Histogram for CKB network connections
pub ckb_message_bytes: HistogramVec,
/// Gauge for CKB rocksdb statistics
Expand Down Expand Up @@ -127,6 +138,14 @@ static METRICS: once_cell::sync::Lazy<Metrics> = once_cell::sync::Lazy::new(|| M
)
.unwrap(),
),
ckb_tx_pool_entry: CkbTxPoolEntryStatistics::from(
&register_int_gauge_vec!(
"ckb_tx_pool_entry",
"CKB tx-pool entry status statistics",
&["type"]
)
.unwrap(),
),
ckb_message_bytes: register_histogram_vec!(
"ckb_message_bytes",
"The CKB message bytes",
Expand Down

0 comments on commit 5e6e709

Please sign in to comment.