From 64fbc6bf3c51ce0c3c4b3be6ebde8cf7909cebb6 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 29 May 2019 15:45:09 +1000 Subject: [PATCH] Add additional metrics to `BeaconChain` --- beacon_node/beacon_chain/src/beacon_chain.rs | 14 ++++++-- beacon_node/beacon_chain/src/metrics.rs | 37 ++++++++++++++++---- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index ce0909510..09bfebb9b 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -530,6 +530,9 @@ impl BeaconChain { /// Produce an `AttestationData` that is valid for the present `slot` and given `shard`. pub fn produce_attestation_data(&self, shard: u64) -> Result { trace!("BeaconChain::produce_attestation: shard: {}", shard); + self.metrics.attestation_production_requests.inc(); + let timer = self.metrics.attestation_production_histogram.start_timer(); + let state = self.state.read(); let current_epoch_start_slot = self @@ -557,6 +560,9 @@ impl BeaconChain { *self.state.read().get_block_root(current_epoch_start_slot)? }; + self.metrics.attestation_production_successes.inc(); + timer.observe_duration(); + Ok(AttestationData { slot: self.state.read().slot, shard, @@ -625,7 +631,8 @@ impl BeaconChain { /// Will accept blocks from prior slots, however it will reject any block from a future slot. pub fn process_block(&self, block: BeaconBlock) -> Result { debug!("Processing block with slot {}...", block.slot); - self.metrics.blocks_processed.inc(); + self.metrics.block_processing_requests.inc(); + let timer = self.metrics.block_processing_historgram.start_timer(); let block_root = block.block_header().canonical_root(); @@ -709,7 +716,8 @@ impl BeaconChain { self.update_state(state)?; } - self.metrics.valid_blocks_processed.inc(); + self.metrics.block_processing_successes.inc(); + timer.observe_duration(); Ok(BlockProcessingOutcome::ValidBlock(ValidBlock::Processed)) } @@ -724,6 +732,7 @@ impl BeaconChain { ) -> Result<(BeaconBlock, BeaconState), BlockProductionError> { debug!("Producing block at slot {}...", self.state.read().slot); self.metrics.block_production_requests.inc(); + let timer = self.metrics.block_production_historgram.start_timer(); let mut state = self.state.read().clone(); @@ -775,6 +784,7 @@ impl BeaconChain { block.state_root = state_root; self.metrics.block_production_successes.inc(); + timer.observe_duration(); Ok((block, state)) } diff --git a/beacon_node/beacon_chain/src/metrics.rs b/beacon_node/beacon_chain/src/metrics.rs index f73db5e13..7c068119e 100644 --- a/beacon_node/beacon_chain/src/metrics.rs +++ b/beacon_node/beacon_chain/src/metrics.rs @@ -1,26 +1,34 @@ pub use prometheus::Error; -use prometheus::{IntCounter, Opts, Registry}; +use prometheus::{Histogram, HistogramOpts, IntCounter, Opts, Registry}; pub struct Metrics { - pub blocks_processed: IntCounter, - pub valid_blocks_processed: IntCounter, + pub block_processing_requests: IntCounter, + pub block_processing_successes: IntCounter, + pub block_processing_historgram: Histogram, pub block_production_requests: IntCounter, pub block_production_successes: IntCounter, + pub block_production_historgram: Histogram, pub attestation_production_requests: IntCounter, pub attestation_production_successes: IntCounter, + pub attestation_production_histogram: Histogram, } impl Metrics { pub fn new() -> Result { Ok(Self { - blocks_processed: { + block_processing_requests: { let opts = Opts::new("blocks_processed", "total_blocks_processed"); IntCounter::with_opts(opts)? }, - valid_blocks_processed: { + block_processing_successes: { let opts = Opts::new("valid_blocks_processed", "total_valid_blocks_processed"); IntCounter::with_opts(opts)? }, + block_processing_historgram: { + let opts = + HistogramOpts::new("block_processing_historgram", "block_processing_time"); + Histogram::with_opts(opts)? + }, block_production_requests: { let opts = Opts::new("block_production_requests", "attempts_to_produce_new_block"); IntCounter::with_opts(opts)? @@ -29,6 +37,11 @@ impl Metrics { let opts = Opts::new("block_production_successes", "blocks_successfully_produced"); IntCounter::with_opts(opts)? }, + block_production_historgram: { + let opts = + HistogramOpts::new("block_production_historgram", "block_production_time"); + Histogram::with_opts(opts)? + }, attestation_production_requests: { let opts = Opts::new( "attestation_production_requests", @@ -43,16 +56,26 @@ impl Metrics { ); IntCounter::with_opts(opts)? }, + attestation_production_histogram: { + let opts = HistogramOpts::new( + "attestation_production_histogram", + "attestation_production_time", + ); + Histogram::with_opts(opts)? + }, }) } pub fn register(&self, registry: &Registry) -> Result<(), Error> { - registry.register(Box::new(self.blocks_processed.clone()))?; - registry.register(Box::new(self.valid_blocks_processed.clone()))?; + registry.register(Box::new(self.block_processing_requests.clone()))?; + registry.register(Box::new(self.block_processing_successes.clone()))?; + registry.register(Box::new(self.block_processing_historgram.clone()))?; registry.register(Box::new(self.block_production_requests.clone()))?; registry.register(Box::new(self.block_production_successes.clone()))?; + registry.register(Box::new(self.block_production_historgram.clone()))?; registry.register(Box::new(self.attestation_production_requests.clone()))?; registry.register(Box::new(self.attestation_production_successes.clone()))?; + registry.register(Box::new(self.attestation_production_histogram.clone()))?; Ok(()) }