mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 21:04:41 +00:00
Unify common metric fns into a crate
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::fork_choice::Error as ForkChoiceError;
|
||||
use crate::metrics::Error as MetricsError;
|
||||
use state_processing::per_block_processing::errors::{
|
||||
AttestationValidationError, IndexedAttestationValidationError,
|
||||
};
|
||||
@@ -34,7 +33,6 @@ pub enum BeaconChainError {
|
||||
MissingBeaconBlock(Hash256),
|
||||
MissingBeaconState(Hash256),
|
||||
SlotProcessingError(SlotProcessingError),
|
||||
MetricsError(String),
|
||||
NoStateForAttestation {
|
||||
beacon_block_root: Hash256,
|
||||
},
|
||||
@@ -44,12 +42,6 @@ pub enum BeaconChainError {
|
||||
|
||||
easy_from_to!(SlotProcessingError, BeaconChainError);
|
||||
|
||||
impl From<MetricsError> for BeaconChainError {
|
||||
fn from(e: MetricsError) -> BeaconChainError {
|
||||
BeaconChainError::MetricsError(format!("{:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum BlockProductionError {
|
||||
UnableToGetBlockRootFromState,
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#[macro_use]
|
||||
extern crate prometheus;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
mod beacon_chain;
|
||||
@@ -18,7 +16,6 @@ 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::{
|
||||
|
||||
@@ -1,67 +1,42 @@
|
||||
pub use prometheus::Error;
|
||||
use prometheus::{Histogram, HistogramTimer, IntCounter, Result};
|
||||
|
||||
pub fn start_timer(histogram: &Result<Histogram>) -> Option<HistogramTimer> {
|
||||
if let Ok(histogram) = histogram {
|
||||
Some(histogram.start_timer())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop_timer(timer: Option<HistogramTimer>) {
|
||||
timer.map(|t| t.observe_duration());
|
||||
}
|
||||
|
||||
pub fn inc_counter(counter: &Result<IntCounter>) {
|
||||
if let Ok(counter) = counter {
|
||||
counter.inc();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn observe(histogram: &Result<Histogram>, value: f64) {
|
||||
if let Ok(histogram) = histogram {
|
||||
histogram.observe(value);
|
||||
}
|
||||
}
|
||||
pub use lighthouse_metrics::*;
|
||||
|
||||
lazy_static! {
|
||||
/*
|
||||
* Block Processing
|
||||
*/
|
||||
pub static ref BLOCK_PROCESSING_DB_READ: Result<Histogram> = register_histogram!(
|
||||
pub static ref BLOCK_PROCESSING_DB_READ: Result<Histogram> = try_create_histogram(
|
||||
"block_processing_db_read_times",
|
||||
"Time spent loading block and state from DB"
|
||||
);
|
||||
pub static ref BLOCK_PROCESSING_REQUESTS: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref BLOCK_PROCESSING_REQUESTS: Result<IntCounter> = try_create_int_counter(
|
||||
"block_processing_requests",
|
||||
"Count of blocks sumbitted for processing"
|
||||
"Count of blocks submitted for processing"
|
||||
);
|
||||
pub static ref BLOCK_PROCESSING_SUCCESSES: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref BLOCK_PROCESSING_SUCCESSES: Result<IntCounter> = try_create_int_counter(
|
||||
"block_processing_successes",
|
||||
"Count of blocks processed without error"
|
||||
);
|
||||
pub static ref BLOCK_PROCESSING_TIMES: Result<Histogram> =
|
||||
register_histogram!("block_processing_times", "Full runtime of block processing");
|
||||
try_create_histogram("block_processing_times", "Full runtime of block processing");
|
||||
|
||||
/*
|
||||
* Block Production
|
||||
*/
|
||||
pub static ref BLOCK_PRODUCTION_REQUESTS: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref BLOCK_PRODUCTION_REQUESTS: Result<IntCounter> = try_create_int_counter(
|
||||
"block_production_requests",
|
||||
"Count of all block production requests"
|
||||
);
|
||||
pub static ref BLOCK_PRODUCTION_SUCCESSES: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref BLOCK_PRODUCTION_SUCCESSES: Result<IntCounter> = try_create_int_counter(
|
||||
"block_production_successes",
|
||||
"Count of blocks sucessfully produced."
|
||||
"Count of blocks successfully produced."
|
||||
);
|
||||
pub static ref BLOCK_PRODUCTION_TIMES: Result<Histogram> =
|
||||
register_histogram!("block_production_times", "Full runtime of block production");
|
||||
try_create_histogram("block_production_times", "Full runtime of block production");
|
||||
|
||||
/*
|
||||
* Block Statistics
|
||||
*/
|
||||
pub static ref OPERATIONS_PER_BLOCK_ATTESTATION: Result<Histogram> = register_histogram!(
|
||||
pub static ref OPERATIONS_PER_BLOCK_ATTESTATION: Result<Histogram> = try_create_histogram(
|
||||
"operations_per_block_attestation",
|
||||
"Number of attestations in a block"
|
||||
);
|
||||
@@ -69,15 +44,15 @@ lazy_static! {
|
||||
/*
|
||||
* Attestation Processing
|
||||
*/
|
||||
pub static ref ATTESTATION_PROCESSING_REQUESTS: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref ATTESTATION_PROCESSING_REQUESTS: Result<IntCounter> = try_create_int_counter(
|
||||
"attestation_processing_requests",
|
||||
"Count of all attestations submitted for processing"
|
||||
);
|
||||
pub static ref ATTESTATION_PROCESSING_SUCCESSES: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref ATTESTATION_PROCESSING_SUCCESSES: Result<IntCounter> = try_create_int_counter(
|
||||
"attestation_processing_successes",
|
||||
"total_attestation_processing_successes"
|
||||
);
|
||||
pub static ref ATTESTATION_PROCESSING_TIMES: Result<Histogram> = register_histogram!(
|
||||
pub static ref ATTESTATION_PROCESSING_TIMES: Result<Histogram> = try_create_histogram(
|
||||
"attestation_processing_times",
|
||||
"Full runtime of attestation processing"
|
||||
);
|
||||
@@ -85,15 +60,15 @@ lazy_static! {
|
||||
/*
|
||||
* Attestation Production
|
||||
*/
|
||||
pub static ref ATTESTATION_PRODUCTION_REQUESTS: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref ATTESTATION_PRODUCTION_REQUESTS: Result<IntCounter> = try_create_int_counter(
|
||||
"attestation_production_requests",
|
||||
"Count of all attestation production requests"
|
||||
);
|
||||
pub static ref ATTESTATION_PRODUCTION_SUCCESSES: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref ATTESTATION_PRODUCTION_SUCCESSES: Result<IntCounter> = try_create_int_counter(
|
||||
"attestation_production_successes",
|
||||
"Count of attestations processed without error"
|
||||
);
|
||||
pub static ref ATTESTATION_PRODUCTION_TIMES: Result<Histogram> = register_histogram!(
|
||||
pub static ref ATTESTATION_PRODUCTION_TIMES: Result<Histogram> = try_create_histogram(
|
||||
"attestation_production_times",
|
||||
"Full runtime of attestation production"
|
||||
);
|
||||
@@ -101,18 +76,18 @@ lazy_static! {
|
||||
/*
|
||||
* Fork Choice
|
||||
*/
|
||||
pub static ref FORK_CHOICE_REQUESTS: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref FORK_CHOICE_REQUESTS: Result<IntCounter> = try_create_int_counter(
|
||||
"fork_choice_requests",
|
||||
"Count of occasions where fork choice has tried to find a head"
|
||||
);
|
||||
pub static ref FORK_CHOICE_CHANGED_HEAD: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref FORK_CHOICE_CHANGED_HEAD: Result<IntCounter> = try_create_int_counter(
|
||||
"fork_choice_changed_head",
|
||||
"Count of occasions fork choice has found a new head"
|
||||
);
|
||||
pub static ref FORK_CHOICE_REORG_COUNT: Result<IntCounter> = register_int_counter!(
|
||||
pub static ref FORK_CHOICE_REORG_COUNT: Result<IntCounter> = try_create_int_counter(
|
||||
"fork_choice_reorg_count",
|
||||
"Count of occasions fork choice has switched to a different chain"
|
||||
);
|
||||
pub static ref FORK_CHOICE_TIMES: Result<Histogram> =
|
||||
register_histogram!("fork_choice_time", "Full runtime of fork choice");
|
||||
try_create_histogram("fork_choice_time", "Full runtime of fork choice");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user