diff --git a/tools/metrics/src/main.rs b/tools/metrics/src/main.rs index 97d48bf..af102d7 100644 --- a/tools/metrics/src/main.rs +++ b/tools/metrics/src/main.rs @@ -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; @@ -66,6 +67,7 @@ fn main() { Wrap::Mempool(m) => { handle_mempool_event(&m.event.unwrap()); } + Wrap::Validation(v) => handle_validation_event(&v.event.unwrap()), } } } @@ -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) => { diff --git a/tools/metrics/src/metrics.rs b/tools/metrics/src/metrics.rs index 794835a..146b165 100644 --- a/tools/metrics/src/metrics.rs +++ b/tools/metrics/src/metrics.rs @@ -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"; @@ -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 = @@ -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(); }