From a3c9c7436e30a9a4dc2d475a46e09d110ac4a6a2 Mon Sep 17 00:00:00 2001 From: 0xb10c Date: Thu, 21 Mar 2024 11:59:24 +0100 Subject: [PATCH] add: Validation BlockConnencted metrics --- tools/metrics/src/main.rs | 18 ++++++++++ tools/metrics/src/metrics.rs | 64 ++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/tools/metrics/src/main.rs b/tools/metrics/src/main.rs index 97d48bf..fa8a793 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,22 @@ 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); + metrics::VALIDATION_BLOCK_CONNECTED_LATEST_TIME_HEIGHT + .with_label_values(&[&v.height.to_string()]) + .set(v.connection_time); + } + } + } + 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..9fcaa95 100644 --- a/tools/metrics/src/metrics.rs +++ b/tools/metrics/src/metrics.rs @@ -1,7 +1,8 @@ use lazy_static::lazy_static; -use prometheus::{self, HistogramVec, IntCounter, IntCounterVec, IntGauge}; +use prometheus::{self, HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec}; use prometheus::{ register_histogram_vec, register_int_counter, register_int_counter_vec, register_int_gauge, + register_int_gauge_vec, HistogramOpts, Opts, }; @@ -14,6 +15,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"; @@ -36,6 +38,7 @@ pub const LABEL_CONN_MISBEHAVING_MESSAGE: &str = "misbehavingmessage"; pub const LABEL_CONN_MISBEHAVING_ID: &str = "id"; pub const LABEL_ADDRMAN_NEW_INSERT_SUCCESS: &str = "inserted"; pub const LABEL_MEMPOOL_REASON: &str = "reason"; +pub const LABEL_VALIDATION_HEIGHT: &str = "height"; pub const BUCKETS_ADDR_ADDRESS_COUNT: [f64; 30] = [ 0f64, 1f64, 2f64, 3f64, 4f64, 5f64, 6f64, 7f64, 8f64, 9f64, 10f64, 15f64, 20f64, 25f64, 30f64, @@ -542,7 +545,7 @@ lazy_static! { .subsystem(SUBSYSTEM_ADDRMAN), ).unwrap(); - // -------------------- Addrman + // -------------------- Mempool /// Number of transactions added to the mempool. pub static ref MEMPOOL_ADDED: IntCounter = @@ -594,4 +597,61 @@ 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(); + + pub static ref VALIDATION_BLOCK_CONNECTED_LATEST_TIME_HEIGHT: IntGaugeVec = + register_int_gauge_vec!( + Opts::new("block_connected_latest_connection_time_height", "Last connected block connection time in µs with height") + .namespace(NAMESPACE) + .subsystem(SUBSYSTEM_VALIDATION), + &[LABEL_VALIDATION_HEIGHT] + ).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(); }