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 Apr 10, 2024
1 parent 37ec28f commit a12ab68
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
15 changes: 15 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,19 @@ 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);
metrics::VALIDATION_BLOCK_CONNECTED_LATEST_SIGOPS.set(v.sigops);
metrics::VALIDATION_BLOCK_CONNECTED_LATEST_INPUTS.set(v.inputs.into());
metrics::VALIDATION_BLOCK_CONNECTED_LATEST_TRANSACTIONS.set(v.transactions);
}
}
}

fn handle_connection_event(cevent: connection_event::Event) {
match cevent {
connection_event::Event::Inbound(i) => {
Expand Down
52 changes: 51 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,53 @@ 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();

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

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

/// Last connected block transactions.
pub static ref VALIDATION_BLOCK_CONNECTED_LATEST_TRANSACTIONS: IntGauge =
register_int_gauge!(
Opts::new("block_connected_latest_transactions", "Last connected block transactions.")
.namespace(NAMESPACE)
.subsystem(SUBSYSTEM_VALIDATION)
).unwrap();
}

0 comments on commit a12ab68

Please sign in to comment.