mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
Monitoring service api (#2251)
## Issue Addressed N/A ## Proposed Changes Adds a client side api for collecting system and process metrics and pushing it to a monitoring service.
This commit is contained in:
@@ -14,6 +14,7 @@ use environment::RuntimeContext;
|
||||
use eth1::{Config as Eth1Config, Service as Eth1Service};
|
||||
use eth2_libp2p::NetworkGlobals;
|
||||
use genesis::{interop_genesis_state, Eth1GenesisService};
|
||||
use monitoring_api::{MonitoringHttpClient, ProcessType};
|
||||
use network::{NetworkConfig, NetworkMessage, NetworkService};
|
||||
use slasher::Slasher;
|
||||
use slasher_service::SlasherService;
|
||||
@@ -374,6 +375,22 @@ where
|
||||
SlasherService::new(beacon_chain, network_send).run(&context.executor)
|
||||
}
|
||||
|
||||
/// Start the explorer client which periodically sends beacon
|
||||
/// and system metrics to the configured endpoint.
|
||||
pub fn monitoring_client(self, config: &monitoring_api::Config) -> Result<Self, String> {
|
||||
let context = self
|
||||
.runtime_context
|
||||
.as_ref()
|
||||
.ok_or("monitoring_client requires a runtime_context")?
|
||||
.service_context("monitoring_client".into());
|
||||
let monitoring_client = MonitoringHttpClient::new(config, context.log().clone())?;
|
||||
monitoring_client.auto_update(
|
||||
context.executor,
|
||||
vec![ProcessType::BeaconNode, ProcessType::System],
|
||||
);
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Immediately starts the service that periodically logs information each slot.
|
||||
pub fn notifier(self) -> Result<Self, String> {
|
||||
let context = self
|
||||
|
||||
@@ -66,6 +66,7 @@ pub struct Config {
|
||||
pub eth1: eth1::Config,
|
||||
pub http_api: http_api::Config,
|
||||
pub http_metrics: http_metrics::Config,
|
||||
pub monitoring_api: Option<monitoring_api::Config>,
|
||||
pub slasher: Option<slasher::Config>,
|
||||
}
|
||||
|
||||
@@ -87,6 +88,7 @@ impl Default for Config {
|
||||
graffiti: Graffiti::default(),
|
||||
http_api: <_>::default(),
|
||||
http_metrics: <_>::default(),
|
||||
monitoring_api: None,
|
||||
slasher: None,
|
||||
validator_monitor_auto: false,
|
||||
validator_monitor_pubkeys: vec![],
|
||||
|
||||
@@ -6,4 +6,14 @@ lazy_static! {
|
||||
"sync_slots_per_second",
|
||||
"The number of blocks being imported per second"
|
||||
);
|
||||
|
||||
pub static ref IS_SYNCED: Result<IntGauge> = try_create_int_gauge(
|
||||
"sync_eth2_synced",
|
||||
"Metric to check if the beacon chain is synced to head. 0 if not synced and non-zero if synced"
|
||||
);
|
||||
|
||||
pub static ref NOTIFIER_HEAD_SLOT: Result<IntGauge> = try_create_int_gauge(
|
||||
"notifier_head_slot",
|
||||
"The head slot sourced from the beacon chain notifier"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,6 +77,9 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
|
||||
};
|
||||
|
||||
let head_slot = head_info.slot;
|
||||
|
||||
metrics::set_gauge(&metrics::NOTIFIER_HEAD_SLOT, head_slot.as_u64() as i64);
|
||||
|
||||
let current_slot = match beacon_chain.slot() {
|
||||
Ok(slot) => slot,
|
||||
Err(e) => {
|
||||
@@ -123,6 +126,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
|
||||
|
||||
// Log if we are syncing
|
||||
if sync_state.is_syncing() {
|
||||
metrics::set_gauge(&metrics::IS_SYNCED, 0);
|
||||
let distance = format!(
|
||||
"{} slots ({})",
|
||||
head_distance.as_u64(),
|
||||
@@ -151,6 +155,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
|
||||
);
|
||||
}
|
||||
} else if sync_state.is_synced() {
|
||||
metrics::set_gauge(&metrics::IS_SYNCED, 1);
|
||||
let block_info = if current_slot > head_slot {
|
||||
" … empty".to_string()
|
||||
} else {
|
||||
@@ -167,6 +172,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
|
||||
"slot" => current_slot,
|
||||
);
|
||||
} else {
|
||||
metrics::set_gauge(&metrics::IS_SYNCED, 0);
|
||||
info!(
|
||||
log,
|
||||
"Searching for peers";
|
||||
|
||||
Reference in New Issue
Block a user