Skip to content

Commit

Permalink
add: Validation BlockConnencted metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
0xB10C committed Mar 21, 2024
1 parent 43c8308 commit d85c1e5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tools/metrics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use shared::net_conn::connection_event;
use shared::net_msg;
use shared::net_msg::{message::Msg, reject::RejectReason};
use shared::util;
use shared::validation::validation_event;
use shared::wrapper;
use shared::wrapper::wrapper::Wrap;

Expand Down Expand Up @@ -66,6 +67,7 @@ fn main() {
Wrap::Mempool(m) => {
handle_mempool_event(&m.event.unwrap());
}
Wrap::Validation(v) => handle_validation_event(&v.event.unwrap()),
}
}
}
Expand Down Expand Up @@ -93,6 +95,16 @@ fn main() {
}
}

fn handle_validation_event(e: &validation_event::Event) {
match e {
validation_event::Event::BlockConnected(v) => {
metrics::VALIDATION_BLOCK_CONNECTED_LATEST_HEIGHT.set(v.height as i64);
metrics::VALIDATION_BLOCK_CONNECTED_LATEST_TIME.set(v.connection_time);
metrics::VALIDATION_BLOCK_CONNECTED_DURATION.inc_by(v.connection_time as u64);
}
}
}

fn handle_connection_event(cevent: connection_event::Event) {
match cevent {
connection_event::Event::Inbound(i) => {
Expand Down
28 changes: 27 additions & 1 deletion tools/metrics/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const SUBSYSTEM_P2P: &str = "p2p";
const SUBSYSTEM_CONN: &str = "conn";
const SUBSYSTEM_ADDRMAN: &str = "addrman";
const SUBSYSTEM_MEMPOOL: &str = "mempool";
const SUBSYSTEM_VALIDATION: &str = "validation";

pub const LABEL_P2P_MSG_TYPE: &str = "message";
pub const LABEL_P2P_CONNECTION_TYPE: &str = "connection_type";
Expand Down Expand Up @@ -542,7 +543,7 @@ lazy_static! {
.subsystem(SUBSYSTEM_ADDRMAN),
).unwrap();

// -------------------- Addrman
// -------------------- Mempool

/// Number of transactions added to the mempool.
pub static ref MEMPOOL_ADDED: IntCounter =
Expand Down Expand Up @@ -594,4 +595,29 @@ lazy_static! {
&[LABEL_MEMPOOL_REASON]
).unwrap();

// -------------------- Validation

/// Last connected block height.
pub static ref VALIDATION_BLOCK_CONNECTED_LATEST_HEIGHT: IntGauge =
register_int_gauge!(
Opts::new("block_connected_latest_height", "Last connected block height.")
.namespace(NAMESPACE)
.subsystem(SUBSYSTEM_VALIDATION)
).unwrap();

/// Last connected block connection time in µs.
pub static ref VALIDATION_BLOCK_CONNECTED_LATEST_TIME: IntGauge =
register_int_gauge!(
Opts::new("block_connected_latest_connection_time", "Last connected block connection time in µs")
.namespace(NAMESPACE)
.subsystem(SUBSYSTEM_VALIDATION)
).unwrap();

/// Total connected block connection time in µs.
pub static ref VALIDATION_BLOCK_CONNECTED_DURATION: IntCounter =
register_int_counter!(
Opts::new("block_connected_connection_time", "Last connected block connection time in µs")
.namespace(NAMESPACE)
.subsystem(SUBSYSTEM_VALIDATION)
).unwrap();
}

0 comments on commit d85c1e5

Please sign in to comment.