Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct datadir disk usage reporting in lighthouse.rs #6741

Open
wants to merge 6 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/eth2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
50 changes: 48 additions & 2 deletions common/eth2/src/lighthouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<String> = 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<String> = std::env::args().collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be re-parsing the CLI args like this. They are already parsed by clap and available in the config

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<Self, String> {
Err("Health is only available on Linux".into())
Expand All @@ -180,8 +221,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
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()
Expand Down Expand Up @@ -223,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(),
})
}
}
Expand Down
Loading