Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prometheus Block Fullness Metrics #3025

Merged
merged 14 commits into from
Feb 1, 2022
3 changes: 3 additions & 0 deletions src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ use crate::types::chainstate::{
StacksAddress, StacksBlockHeader, StacksBlockId, StacksMicroblockHeader,
};
use crate::{types, util};
use monitoring::set_last_execution_cost_observed;
use types::chainstate::BurnchainHeaderHash;

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -5240,6 +5241,8 @@ impl StacksChainState {

chainstate_tx.log_transactions_processed(&new_tip.index_block_hash(), &tx_receipts);

set_last_execution_cost_observed(&block_execution_cost);

let epoch_receipt = StacksEpochReceipt {
header: new_tip,
tx_receipts,
Expand Down
15 changes: 15 additions & 0 deletions src/monitoring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use std::sync::Mutex;
use util::db::sqlite_open;
use util::db::Error as DatabaseError;
use util::uint::{Uint256, Uint512};
use vm::costs::ExecutionCost;

#[cfg(feature = "monitoring_prom")]
mod prometheus;
Expand Down Expand Up @@ -104,6 +105,20 @@ pub fn increment_btc_blocks_received_counter() {
prometheus::BTC_BLOCKS_RECEIVED_COUNTER.inc();
}

#[allow(unused_variables)]
pub fn set_last_execution_cost_observed(execution_cost: &ExecutionCost) {
#[cfg(feature = "monitoring_prom")]
Copy link
Member

@jcnelson jcnelson Feb 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to just group all of these statements inside a single #[cfg(feature = "monitoring_prom")]? Something like:

#[cfg(feature = "monitoring_prom")] {
   /* do stuff here */
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this

prometheus::LAST_EXECUTION_READ_COUNT.set(execution_cost.read_count.try_into().unwrap());
kantai marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(feature = "monitoring_prom")]
prometheus::LAST_EXECUTION_WRITE_COUNT.set(execution_cost.write_count.try_into().unwrap());
#[cfg(feature = "monitoring_prom")]
prometheus::LAST_EXECUTION_READ_LENGTH.set(execution_cost.read_length.try_into().unwrap());
#[cfg(feature = "monitoring_prom")]
prometheus::LAST_EXECUTION_WRITE_LENGTH.set(execution_cost.write_length.try_into().unwrap());
#[cfg(feature = "monitoring_prom")]
prometheus::LAST_EXECUTION_RUNTIME.set(execution_cost.runtime.try_into().unwrap());
}

pub fn increment_btc_ops_sent_counter() {
#[cfg(feature = "monitoring_prom")]
prometheus::BTC_OPS_SENT_COUNTER.inc();
Expand Down
25 changes: 25 additions & 0 deletions src/monitoring/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ lazy_static! {
"Total number of error logs emitted by node"
)).unwrap();

pub static ref LAST_EXECUTION_READ_COUNT: IntGauge = register_int_gauge!(opts!(
"execution_cost_read_count",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these could be slightly more descriptively named for prometheus as last_block_read_count, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the variable name or the caption part?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the prometheus metric name, i.e.

    pub static ref LAST_EXECUTION_READ_COUNT: IntGauge = register_int_gauge!(opts!(
        "last_block_read_count",

Copy link
Member

@CharlieC3 CharlieC3 Jan 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also prepend stacks_node_ to each metric name like we do for the other stacks-node metrics? It helps with search and discovery, especially when your Prometheus deployment could have hundreds of metrics from all kinds of services. Reference
Screen Shot 2022-01-31 at 3 24 23 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with stacks_node_last_block_read_count-style prefix.

"`execution_cost_read_count` for the last block observed."
)).unwrap();

pub static ref LAST_EXECUTION_WRITE_COUNT: IntGauge = register_int_gauge!(opts!(
"execution_cost_write_count",
"`execution_cost_write_count` for the last block observed."
)).unwrap();

pub static ref LAST_EXECUTION_READ_LENGTH: IntGauge = register_int_gauge!(opts!(
"execution_cost_read_length",
"`execution_cost_read_length` for the last block observed."
)).unwrap();

pub static ref LAST_EXECUTION_WRITE_LENGTH: IntGauge = register_int_gauge!(opts!(
"execution_cost_write_length",
"`execution_cost_write_length` for the last block observed."
)).unwrap();

pub static ref LAST_EXECUTION_RUNTIME: IntGauge = register_int_gauge!(opts!(
"execution_cost_runtime",
"`execution_cost_runtime` for the last block observed."
)).unwrap();

pub static ref ACTIVE_MINERS_COUNT_GAUGE: IntGauge = register_int_gauge!(opts!(
"stacks_node_active_miners_total",
"Total number of active miners"
Expand Down