diff --git a/src/chainstate/stacks/db/blocks.rs b/src/chainstate/stacks/db/blocks.rs index e9d9ff8dfd..0a45e14896 100644 --- a/src/chainstate/stacks/db/blocks.rs +++ b/src/chainstate/stacks/db/blocks.rs @@ -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)] @@ -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, @@ -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, diff --git a/src/monitoring/mod.rs b/src/monitoring/mod.rs index bc38e98fde..4d9f6fa49e 100644 --- a/src/monitoring/mod.rs +++ b/src/monitoring/mod.rs @@ -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; @@ -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(); @@ -397,6 +420,7 @@ pub fn set_burnchain_signer(signer: BurnchainSigner) -> Result<(), SetGlobalBurn Ok(()) } +#[allow(unreachable_code)] pub fn get_burnchain_signer() -> Option { #[cfg(feature = "monitoring_prom")] { diff --git a/src/monitoring/prometheus.rs b/src/monitoring/prometheus.rs index 0154e8ff55..9a9d7f8f46 100644 --- a/src/monitoring/prometheus.rs +++ b/src/monitoring/prometheus.rs @@ -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"