Add sync-speed metric (#898)

This commit is contained in:
Paul Hauner 2020-03-18 09:25:29 +11:00 committed by GitHub
parent c198bddf9e
commit 3c8fe00510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 0 deletions

2
Cargo.lock generated
View File

@ -520,7 +520,9 @@ dependencies = [
"exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"genesis 0.1.0",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lighthouse_bootstrap 0.1.0",
"lighthouse_metrics 0.1.0",
"network 0.1.0",
"parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"prometheus 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -38,3 +38,5 @@ genesis = { path = "../genesis" }
environment = { path = "../../lighthouse/environment" }
lighthouse_bootstrap = { path = "../../eth2/utils/lighthouse_bootstrap" }
eth2_ssz = { path = "../../eth2/utils/ssz" }
lazy_static = "1.4.0"
lighthouse_metrics = { path = "../../eth2/utils/lighthouse_metrics" }

View File

@ -1,6 +1,7 @@
extern crate slog;
pub mod config;
mod metrics;
mod notifier;
pub mod builder;

View File

@ -0,0 +1,9 @@
use lazy_static::lazy_static;
pub use lighthouse_metrics::*;
lazy_static! {
pub static ref SYNC_SLOTS_PER_SECOND: Result<IntGauge> = try_create_int_gauge(
"sync_slots_per_second",
"The number of blocks being imported per second"
);
}

View File

@ -1,3 +1,4 @@
use crate::metrics;
use beacon_chain::{BeaconChain, BeaconChainTypes};
use environment::RuntimeContext;
use exit_future::Signal;
@ -83,6 +84,8 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
let mut speedo = speedo.lock();
speedo.observe(head_slot, Instant::now());
metrics::set_gauge(&metrics::SYNC_SLOTS_PER_SECOND, speedo.slots_per_second().unwrap_or_else(|| 0_f64) as i64);
// The next two lines take advantage of saturating subtraction on `Slot`.
let head_distance = current_slot - head_slot;