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 30, 2024
1 parent 37ec28f commit a3c9c74
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
18 changes: 18 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,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) => {
Expand Down
64 changes: 62 additions & 2 deletions tools/metrics/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand All @@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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();
}

0 comments on commit a3c9c74

Please sign in to comment.