diff --git a/Cargo.lock b/Cargo.lock index ce0a7e69ab..895423b9ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", diff --git a/beacon_node/client/Cargo.toml b/beacon_node/client/Cargo.toml index 8feed866e4..a53ce5455c 100644 --- a/beacon_node/client/Cargo.toml +++ b/beacon_node/client/Cargo.toml @@ -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" } diff --git a/beacon_node/client/src/lib.rs b/beacon_node/client/src/lib.rs index 6f1214ce50..0d5155c6f1 100644 --- a/beacon_node/client/src/lib.rs +++ b/beacon_node/client/src/lib.rs @@ -1,6 +1,7 @@ extern crate slog; pub mod config; +mod metrics; mod notifier; pub mod builder; diff --git a/beacon_node/client/src/metrics.rs b/beacon_node/client/src/metrics.rs new file mode 100644 index 0000000000..5598fde220 --- /dev/null +++ b/beacon_node/client/src/metrics.rs @@ -0,0 +1,9 @@ +use lazy_static::lazy_static; +pub use lighthouse_metrics::*; + +lazy_static! { + pub static ref SYNC_SLOTS_PER_SECOND: Result = try_create_int_gauge( + "sync_slots_per_second", + "The number of blocks being imported per second" + ); +} diff --git a/beacon_node/client/src/notifier.rs b/beacon_node/client/src/notifier.rs index eddebce1f3..85e15049ec 100644 --- a/beacon_node/client/src/notifier.rs +++ b/beacon_node/client/src/notifier.rs @@ -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( 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;