mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
Health Endpoints for UI (#3668)
This PR adds some health endpoints for the beacon node and the validator client. Specifically it adds the endpoint: `/lighthouse/ui/health` These are not entirely stable yet. But provide a base for modification for our UI. These also may have issues with various platforms and may need modification.
This commit is contained in:
@@ -16,6 +16,7 @@ use eth2::lighthouse_vc::{
|
||||
types::{self as api_types, GenericResponse, PublicKey, PublicKeyBytes},
|
||||
};
|
||||
use lighthouse_version::version_with_platform;
|
||||
use parking_lot::RwLock;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use slog::{crit, info, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
@@ -24,6 +25,8 @@ use std::marker::PhantomData;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use sysinfo::{System, SystemExt};
|
||||
use system_health::observe_system_health_vc;
|
||||
use task_executor::TaskExecutor;
|
||||
use types::{ChainSpec, ConfigAndPreset, EthSpec};
|
||||
use validator_dir::Builder as ValidatorDirBuilder;
|
||||
@@ -183,6 +186,35 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
let api_token_path_inner = api_token_path.clone();
|
||||
let api_token_path_filter = warp::any().map(move || api_token_path_inner.clone());
|
||||
|
||||
// Create a `warp` filter that provides access to local system information.
|
||||
let system_info = Arc::new(RwLock::new(sysinfo::System::new()));
|
||||
{
|
||||
// grab write access for initialisation
|
||||
let mut system_info = system_info.write();
|
||||
system_info.refresh_disks_list();
|
||||
system_info.refresh_networks_list();
|
||||
} // end lock
|
||||
|
||||
let system_info_filter =
|
||||
warp::any()
|
||||
.map(move || system_info.clone())
|
||||
.map(|sysinfo: Arc<RwLock<System>>| {
|
||||
{
|
||||
// refresh stats
|
||||
let mut sysinfo_lock = sysinfo.write();
|
||||
sysinfo_lock.refresh_memory();
|
||||
sysinfo_lock.refresh_cpu_specifics(sysinfo::CpuRefreshKind::everything());
|
||||
sysinfo_lock.refresh_cpu();
|
||||
sysinfo_lock.refresh_system();
|
||||
sysinfo_lock.refresh_networks();
|
||||
sysinfo_lock.refresh_disks();
|
||||
} // end lock
|
||||
sysinfo
|
||||
});
|
||||
|
||||
let app_start = std::time::Instant::now();
|
||||
let app_start_filter = warp::any().map(move || app_start);
|
||||
|
||||
// GET lighthouse/version
|
||||
let get_node_version = warp::path("lighthouse")
|
||||
.and(warp::path("version"))
|
||||
@@ -279,6 +311,24 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
},
|
||||
);
|
||||
|
||||
// GET lighthouse/ui/health
|
||||
let get_lighthouse_ui_health = warp::path("lighthouse")
|
||||
.and(warp::path("ui"))
|
||||
.and(warp::path("health"))
|
||||
.and(warp::path::end())
|
||||
.and(system_info_filter)
|
||||
.and(app_start_filter)
|
||||
.and(validator_dir_filter.clone())
|
||||
.and(signer.clone())
|
||||
.and_then(|sysinfo, app_start: std::time::Instant, val_dir, signer| {
|
||||
blocking_signed_json_task(signer, move || {
|
||||
let app_uptime = app_start.elapsed().as_secs() as u64;
|
||||
Ok(api_types::GenericResponse::from(observe_system_health_vc(
|
||||
sysinfo, val_dir, app_uptime,
|
||||
)))
|
||||
})
|
||||
});
|
||||
|
||||
// POST lighthouse/validators/
|
||||
let post_validators = warp::path("lighthouse")
|
||||
.and(warp::path("validators"))
|
||||
@@ -894,6 +944,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.or(get_lighthouse_spec)
|
||||
.or(get_lighthouse_validators)
|
||||
.or(get_lighthouse_validators_pubkey)
|
||||
.or(get_lighthouse_ui_health)
|
||||
.or(get_fee_recipient)
|
||||
.or(get_gas_limit)
|
||||
.or(get_std_keystores)
|
||||
|
||||
Reference in New Issue
Block a user