diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index fe05f55a01a..7e1fba73140 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -4039,9 +4039,10 @@ pub fn serve( .and(warp::path("health")) .and(warp::path::end()) .and(task_spawner_filter.clone()) - .then(|task_spawner: TaskSpawner| { + .and(client_config_filter.clone()) + .then(|task_spawner: TaskSpawner, config: Arc| { task_spawner.blocking_json_task(Priority::P0, move || { - eth2::lighthouse::Health::observe() + eth2::lighthouse::Health::observe(&config) .map(api_types::GenericResponse::from) .map_err(warp_utils::reject::custom_bad_request) }) diff --git a/common/eth2/Cargo.toml b/common/eth2/Cargo.toml index d23a4068f1b..c82e602bd9f 100644 --- a/common/eth2/Cargo.toml +++ b/common/eth2/Cargo.toml @@ -30,6 +30,7 @@ slashing_protection = { workspace = true } mediatype = "0.19.13" pretty_reqwest_error = { workspace = true } derivative = { workspace = true } +client = { path = "../../beacon_node/client" } [dev-dependencies] tokio = { workspace = true } diff --git a/common/eth2/src/lighthouse.rs b/common/eth2/src/lighthouse.rs index 66dd5d779bd..274c737cc0b 100644 --- a/common/eth2/src/lighthouse.rs +++ b/common/eth2/src/lighthouse.rs @@ -18,6 +18,11 @@ use serde::{Deserialize, Serialize}; use ssz::four_byte_option_impl; use ssz_derive::{Decode, Encode}; use store::{AnchorInfo, BlobInfo, Split, StoreConfig}; +use beacon_node::config::get_data_dir; +use clap::ArgMatches; +use client::Config as ClientConfig; +use directory::{DEFAULT_BEACON_NODE_DIR, DEFAULT_ROOT_DIR}; +use std::path::PathBuf; pub use attestation_performance::{ AttestationPerformance, AttestationPerformanceQuery, AttestationPerformanceStatistics, @@ -162,16 +167,18 @@ pub struct SystemHealth { pub misc_node_boot_ts_seconds: u64, /// OS pub misc_os: String, + /// Data directory path + pub data_dir: String, } impl SystemHealth { #[cfg(not(target_os = "linux"))] - pub fn observe() -> Result { + pub fn observe(_config: &ClientConfig) -> Result { Err("Health is only available on Linux".into()) } #[cfg(target_os = "linux")] - pub fn observe() -> Result { + pub fn observe(config: &ClientConfig) -> Result { let vm = psutil::memory::virtual_memory() .map_err(|e| format!("Unable to get virtual memory: {:?}", e))?; let loadavg = @@ -180,8 +187,12 @@ impl SystemHealth { let cpu = psutil::cpu::cpu_times().map_err(|e| format!("Unable to get cpu times: {:?}", e))?; - let disk_usage = psutil::disk::disk_usage("/") - .map_err(|e| format!("Unable to disk usage info: {:?}", e))?; + // Get the data directory from provided config + let data_dir = config.get_data_dir(); + let data_dir_str = data_dir.to_str().unwrap_or("/"); + + let disk_usage = psutil::disk::disk_usage(data_dir_str) + .map_err(|e| format!("Unable to get disk usage info for {:?}: {:?}", data_dir, e))?; let disk = psutil::disk::DiskIoCountersCollector::default() .disk_io_counters() @@ -223,6 +234,7 @@ impl SystemHealth { network_node_bytes_total_transmit: net.bytes_sent(), misc_node_boot_ts_seconds: boot_time, misc_os: std::env::consts::OS.to_string(), + data_dir: data_dir_str.to_string(), }) } } @@ -284,15 +296,15 @@ impl ProcessHealth { impl Health { #[cfg(not(target_os = "linux"))] - pub fn observe() -> Result { + pub fn observe(_config: &ClientConfig) -> Result { Err("Health is only available on Linux".into()) } #[cfg(target_os = "linux")] - pub fn observe() -> Result { + pub fn observe(config: &ClientConfig) -> Result { Ok(Self { process: ProcessHealth::observe()?, - system: SystemHealth::observe()?, + system: SystemHealth::observe(config)?, }) } }