mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 12:58:31 +00:00
Fix broken beacon chain metrics, add slot clock metrics
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#![recursion_limit = "128"] // For lazy-static
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{BeaconChain, BeaconChainTypes};
|
||||
pub use lighthouse_metrics::*;
|
||||
use types::{BeaconState, Epoch, EthSpec, Hash256, Slot};
|
||||
use types::{BeaconState, Epoch, Hash256, Slot};
|
||||
|
||||
lazy_static! {
|
||||
/*
|
||||
@@ -140,17 +140,6 @@ lazy_static! {
|
||||
*/
|
||||
pub static ref PERSIST_CHAIN: Result<Histogram> =
|
||||
try_create_histogram("beacon_persist_chain", "Time taken to update the canonical head");
|
||||
}
|
||||
|
||||
// Lazy-static is split so we don't reach the crate-level recursion limit.
|
||||
lazy_static! {
|
||||
/*
|
||||
* Slot Clock
|
||||
*/
|
||||
pub static ref PRESENT_SLOT: Result<IntGauge> =
|
||||
try_create_int_gauge("beacon_present_slot", "The present slot, according to system time");
|
||||
pub static ref PRESENT_EPOCH: Result<IntGauge> =
|
||||
try_create_int_gauge("beacon_present_epoch", "The present epoch, according to system time");
|
||||
|
||||
/*
|
||||
* Chain Head
|
||||
@@ -194,21 +183,6 @@ lazy_static! {
|
||||
/// Scrape the `beacon_chain` for metrics that are not constantly updated (e.g., the present slot,
|
||||
/// head state info, etc) and update the Prometheus `DEFAULT_REGISTRY`.
|
||||
pub fn scrape_for_metrics<T: BeaconChainTypes>(beacon_chain: &BeaconChain<T>) {
|
||||
set_gauge_by_slot(
|
||||
&PRESENT_SLOT,
|
||||
beacon_chain
|
||||
.read_slot_clock()
|
||||
.unwrap_or_else(|| Slot::new(0)),
|
||||
);
|
||||
|
||||
set_gauge_by_epoch(
|
||||
&PRESENT_EPOCH,
|
||||
beacon_chain
|
||||
.read_slot_clock()
|
||||
.map(|s| s.epoch(T::EthSpec::slots_per_epoch()))
|
||||
.unwrap_or_else(|| Epoch::new(0)),
|
||||
);
|
||||
|
||||
scrape_head_state::<T>(
|
||||
&beacon_chain.head().beacon_state,
|
||||
beacon_chain.head().beacon_state_root,
|
||||
|
||||
@@ -26,3 +26,4 @@ tokio = "0.1.17"
|
||||
url = "2.0"
|
||||
lazy_static = "1.3.0"
|
||||
lighthouse_metrics = { path = "../../eth2/utils/lighthouse_metrics" }
|
||||
slot_clock = { path = "../../eth2/utils/slot_clock" }
|
||||
|
||||
@@ -39,6 +39,23 @@ pub fn get_prometheus<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiR
|
||||
.get::<DBPath>()
|
||||
.ok_or_else(|| ApiError::ServerError("DBPath extension missing".to_string()))?;
|
||||
|
||||
// There are two categories of metrics:
|
||||
//
|
||||
// - Dynamically updated: things like histograms and event counters that are updated on the
|
||||
// fly.
|
||||
// - Statically updated: things which are only updated at the time of the scrape (used where we
|
||||
// can avoid cluttering up code with metrics calls).
|
||||
//
|
||||
// The `prometheus` crate has a `DEFAULT_REGISTRY` global singleton (via `lazy_static`) which
|
||||
// keeps the state of all the metrics. Dynamically updated things will already be up-to-date in
|
||||
// the registry (because they update themselves) however statically updated things need to be
|
||||
// "scraped".
|
||||
//
|
||||
// We proceed by, first updating all the static metrics using `scrape_for_metrics(..)`. Then,
|
||||
// using `prometheus::gather(..)` to collect the global `DEFAULT_REGISTRY` metrics into a
|
||||
// string that can be returned via HTTP.
|
||||
|
||||
slot_clock::scrape_for_metrics::<T::EthSpec, T::SlotClock>(&beacon_chain.slot_clock);
|
||||
store::scrape_for_metrics(&db_path);
|
||||
beacon_chain::scrape_for_metrics(&beacon_chain);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user