Begin metrics refactor

This commit is contained in:
Paul Hauner
2019-08-11 12:12:19 +10:00
parent 4020d13064
commit 48733917be
7 changed files with 46 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ use crate::checkpoint::CheckPoint;
use crate::errors::{BeaconChainError as Error, BlockProductionError};
use crate::fork_choice::{Error as ForkChoiceError, ForkChoice};
use crate::iter::{ReverseBlockRootIterator, ReverseStateRootIterator};
use crate::metrics;
use crate::metrics::Metrics;
use crate::persisted_beacon_chain::{PersistedBeaconChain, BEACON_CHAIN_DB_KEY};
use lmd_ghost::LmdGhost;
@@ -848,6 +849,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
return Ok(BlockProcessingOutcome::BlockIsAlreadyKnown);
}
// Records the time taken to load the block and state from the database during block
// processing.
let db_read_timer = metrics::BLOCK_PROCESSING_DB_READ.start_timer();
// Load the blocks parent block from the database, returning invalid if that block is not
// found.
let parent_block: BeaconBlock<T::EthSpec> = match self.store.get(&block.parent_root)? {
@@ -867,6 +872,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.get(&parent_state_root)?
.ok_or_else(|| Error::DBInconsistent(format!("Missing state {}", parent_state_root)))?;
db_read_timer.observe_duration();
// Transition the parent state to the block slot.
let mut state: BeaconState<T::EthSpec> = parent_state;
for _ in state.slot.as_u64()..block.slot.as_u64() {

View File

@@ -1,3 +1,8 @@
#[macro_use]
extern crate prometheus;
#[macro_use]
extern crate lazy_static;
mod beacon_chain;
mod checkpoint;
mod errors;
@@ -13,6 +18,7 @@ pub use self::beacon_chain::{
pub use self::checkpoint::CheckPoint;
pub use self::errors::{BeaconChainError, BlockProductionError};
pub use lmd_ghost;
pub use metrics::gather_metrics;
pub use parking_lot;
pub use slot_clock;
pub use state_processing::per_block_processing::errors::{

View File

@@ -1,6 +1,18 @@
pub use prometheus::Error;
use prometheus::{Histogram, HistogramOpts, IntCounter, Opts, Registry};
lazy_static! {
pub static ref BLOCK_PROCESSING_DB_READ: Histogram = register_histogram!(
"block_processing_db_read_times",
"Time spent loading block and state from DB"
)
.unwrap();
}
pub fn gather_metrics() -> Vec<prometheus::proto::MetricFamily> {
prometheus::gather()
}
pub struct Metrics {
pub block_processing_requests: IntCounter,
pub block_processing_successes: IntCounter,