Skip to content

Commit

Permalink
Merge pull request #3025 from stacks-network/feat/prometheus-fullness
Browse files Browse the repository at this point in the history
feat: Prometheus Block Fullness Metrics
  • Loading branch information
gregorycoppola authored Feb 1, 2022
2 parents ca36b2e + b88d8ce commit ff18dfc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
8 changes: 8 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 @@ -5008,6 +5009,11 @@ impl StacksChainState {
None,
)?;

let block_limit = clarity_tx.block_limit().unwrap_or_else(|| {
warn!("Failed to read transaction block limit");
ExecutionCost::max_value()
});

let (
scheduled_miner_reward,
block_execution_cost,
Expand Down Expand Up @@ -5250,6 +5256,8 @@ impl StacksChainState {

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

set_last_execution_cost_observed(&block_execution_cost, &block_limit);

let epoch_receipt = StacksEpochReceipt {
header: new_tip,
tx_receipts,
Expand Down
24 changes: 24 additions & 0 deletions src/monitoring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ use crate::{
},
};
use burnchains::BurnchainSigner;
use std::convert::TryInto;
use std::error::Error;
use std::sync::atomic::{AtomicUsize, Ordering};
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 +106,27 @@ pub fn increment_btc_blocks_received_counter() {
prometheus::BTC_BLOCKS_RECEIVED_COUNTER.inc();
}

/// Log `execution_cost` as a ratio of `block_limit`.
#[allow(unused_variables)]
pub fn set_last_execution_cost_observed(
execution_cost: &ExecutionCost,
block_limit: &ExecutionCost,
) {
#[cfg(feature = "monitoring_prom")]
{
prometheus::LAST_BLOCK_READ_COUNT
.set(execution_cost.read_count as f64 / block_limit.read_count as f64);
prometheus::LAST_BLOCK_WRITE_COUNT
.set(execution_cost.write_count as f64 / block_limit.read_count as f64);
prometheus::LAST_BLOCK_READ_LENGTH
.set(execution_cost.read_length as f64 / block_limit.read_length as f64);
prometheus::LAST_BLOCK_WRITE_LENGTH
.set(execution_cost.write_length as f64 / block_limit.write_length as f64);
prometheus::LAST_BLOCK_RUNTIME
.set(execution_cost.runtime as f64 / block_limit.runtime as f64);
}
}

pub fn increment_btc_ops_sent_counter() {
#[cfg(feature = "monitoring_prom")]
prometheus::BTC_OPS_SENT_COUNTER.inc();
Expand Down Expand Up @@ -397,6 +420,7 @@ pub fn set_burnchain_signer(signer: BurnchainSigner) -> Result<(), SetGlobalBurn
Ok(())
}

#[allow(unreachable_code)]
pub fn get_burnchain_signer() -> Option<BurnchainSigner> {
#[cfg(feature = "monitoring_prom")]
{
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_BLOCK_READ_COUNT: Gauge = register_gauge!(opts!(
"stacks_node_last_block_read_count",
"`execution_cost_read_count` for the last block observed."
)).unwrap();

pub static ref LAST_BLOCK_WRITE_COUNT: Gauge = register_gauge!(opts!(
"stacks_node_last_block_write_count",
"`execution_cost_write_count` for the last block observed."
)).unwrap();

pub static ref LAST_BLOCK_READ_LENGTH: Gauge = register_gauge!(opts!(
"stacks_node_last_block_read_length",
"`execution_cost_read_length` for the last block observed."
)).unwrap();

pub static ref LAST_BLOCK_WRITE_LENGTH: Gauge = register_gauge!(opts!(
"stacks_node_last_block_write_length",
"`execution_cost_write_length` for the last block observed."
)).unwrap();

pub static ref LAST_BLOCK_RUNTIME: Gauge = register_gauge!(opts!(
"stacks_node_last_block_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

0 comments on commit ff18dfc

Please sign in to comment.