From a06097597b2ab8cf44039e6c9d02f3dd2b0f0c8d Mon Sep 17 00:00:00 2001 From: crStiv Date: Thu, 26 Dec 2024 02:38:40 +0100 Subject: [PATCH 1/6] Update lighthouse.rs Fix disk usage metrics to show datadir usage instead of root --- common/eth2/src/lighthouse.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/eth2/src/lighthouse.rs b/common/eth2/src/lighthouse.rs index 66dd5d779bd..152a39396cc 100644 --- a/common/eth2/src/lighthouse.rs +++ b/common/eth2/src/lighthouse.rs @@ -180,7 +180,9 @@ 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("/") + let data_dir = std::env::var("LIGHTHOUSE_DATADIR").unwrap_or_else(|_| "/".to_string()); + + let disk_usage = psutil::disk::disk_usage(&data_dir) .map_err(|e| format!("Unable to disk usage info: {:?}", e))?; let disk = psutil::disk::DiskIoCountersCollector::default() From 98d8ef4fa0c24457129b021609a418721b0e5b56 Mon Sep 17 00:00:00 2001 From: crStiv Date: Thu, 26 Dec 2024 02:51:04 +0100 Subject: [PATCH 2/6] Update lighthouse.rs --- common/eth2/src/lighthouse.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/eth2/src/lighthouse.rs b/common/eth2/src/lighthouse.rs index 152a39396cc..9dab12bb94e 100644 --- a/common/eth2/src/lighthouse.rs +++ b/common/eth2/src/lighthouse.rs @@ -180,10 +180,13 @@ impl SystemHealth { let cpu = psutil::cpu::cpu_times().map_err(|e| format!("Unable to get cpu times: {:?}", e))?; - let data_dir = std::env::var("LIGHTHOUSE_DATADIR").unwrap_or_else(|_| "/".to_string()); + let data_dir = lighthouse_metrics::get_data_dir() + .map_err(|e| format!("Unable to get data directory path: {:?}", e))? + .to_str() + .unwrap_or("/"); - let disk_usage = psutil::disk::disk_usage(&data_dir) - .map_err(|e| format!("Unable to disk usage info: {:?}", e))?; + let disk_usage = psutil::disk::disk_usage(data_dir) + .map_err(|e| format!("Unable to get disk usage info for {}: {:?}", data_dir, e))?; let disk = psutil::disk::DiskIoCountersCollector::default() .disk_io_counters() From 8a1e7561f6e8cc7ececd4166df74e425ebb63839 Mon Sep 17 00:00:00 2001 From: crStiv Date: Sat, 28 Dec 2024 00:41:10 +0100 Subject: [PATCH 3/6] Update lighthouse.rs --- common/eth2/src/lighthouse.rs | 55 ++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/common/eth2/src/lighthouse.rs b/common/eth2/src/lighthouse.rs index 9dab12bb94e..93767125aee 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,9 +167,45 @@ pub struct SystemHealth { pub misc_node_boot_ts_seconds: u64, /// OS pub misc_os: String, + /// Data directory path + pub data_dir: String, } impl SystemHealth { + /// Gets the network which should be used. + fn get_network() -> String { + // Try to get network from command line arguments + let args: Vec = std::env::args().collect(); + if let Some(pos) = args.iter().position(|x| x == "--network") { + if pos + 1 < args.len() { + return args[pos + 1].clone(); + } + } + + // Default to mainnet + "mainnet".to_string() + } + + /// Gets the datadir which should be used. + fn get_data_dir() -> PathBuf { + // Try to get datadir from command line arguments + let args: Vec = std::env::args().collect(); + if let Some(pos) = args.iter().position(|x| x == "--datadir") { + if pos + 1 < args.len() { + return PathBuf::from(&args[pos + 1]).join(DEFAULT_BEACON_NODE_DIR); + } + } + + // If not found in args, use default path + dirs::home_dir() + .map(|home| { + home.join(DEFAULT_ROOT_DIR) + .join(Self::get_network()) + .join(DEFAULT_BEACON_NODE_DIR) + }) + .unwrap_or_else(|| PathBuf::from("/")) + } + #[cfg(not(target_os = "linux"))] pub fn observe() -> Result { Err("Health is only available on Linux".into()) @@ -180,13 +221,12 @@ impl SystemHealth { let cpu = psutil::cpu::cpu_times().map_err(|e| format!("Unable to get cpu times: {:?}", e))?; - let data_dir = lighthouse_metrics::get_data_dir() - .map_err(|e| format!("Unable to get data directory path: {:?}", e))? - .to_str() - .unwrap_or("/"); - - let disk_usage = psutil::disk::disk_usage(data_dir) - .map_err(|e| format!("Unable to get disk usage info for {}: {:?}", data_dir, e))?; + // Get the data directory + let data_dir = Self::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() @@ -228,6 +268,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(), }) } } From 99d5e61656b4d25349c86899fdd3245c5c15607d Mon Sep 17 00:00:00 2001 From: crStiv Date: Sat, 28 Dec 2024 00:42:04 +0100 Subject: [PATCH 4/6] Update Cargo.toml --- common/eth2/Cargo.toml | 1 + 1 file changed, 1 insertion(+) 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 } From fe739279cfe66ec4d2f4088729c9150371980ad2 Mon Sep 17 00:00:00 2001 From: crStiv Date: Sat, 28 Dec 2024 13:25:03 +0100 Subject: [PATCH 5/6] Update lighthouse.rs --- common/eth2/src/lighthouse.rs | 48 +++++------------------------------ 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/common/eth2/src/lighthouse.rs b/common/eth2/src/lighthouse.rs index 93767125aee..274c737cc0b 100644 --- a/common/eth2/src/lighthouse.rs +++ b/common/eth2/src/lighthouse.rs @@ -172,47 +172,13 @@ pub struct SystemHealth { } impl SystemHealth { - /// Gets the network which should be used. - fn get_network() -> String { - // Try to get network from command line arguments - let args: Vec = std::env::args().collect(); - if let Some(pos) = args.iter().position(|x| x == "--network") { - if pos + 1 < args.len() { - return args[pos + 1].clone(); - } - } - - // Default to mainnet - "mainnet".to_string() - } - - /// Gets the datadir which should be used. - fn get_data_dir() -> PathBuf { - // Try to get datadir from command line arguments - let args: Vec = std::env::args().collect(); - if let Some(pos) = args.iter().position(|x| x == "--datadir") { - if pos + 1 < args.len() { - return PathBuf::from(&args[pos + 1]).join(DEFAULT_BEACON_NODE_DIR); - } - } - - // If not found in args, use default path - dirs::home_dir() - .map(|home| { - home.join(DEFAULT_ROOT_DIR) - .join(Self::get_network()) - .join(DEFAULT_BEACON_NODE_DIR) - }) - .unwrap_or_else(|| PathBuf::from("/")) - } - #[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 = @@ -221,8 +187,8 @@ impl SystemHealth { let cpu = psutil::cpu::cpu_times().map_err(|e| format!("Unable to get cpu times: {:?}", e))?; - // Get the data directory - let data_dir = Self::get_data_dir(); + // 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) @@ -330,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)?, }) } } From 36e197e8f3af792536df3173cd2094418d62005b Mon Sep 17 00:00:00 2001 From: crStiv Date: Sat, 28 Dec 2024 13:26:14 +0100 Subject: [PATCH 6/6] Update lib.rs --- beacon_node/http_api/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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) })