Skip to content

Commit

Permalink
Merge pull request #4 from sfcompute/kenny/storage_totals
Browse files Browse the repository at this point in the history
Add Motherboard Info Collection and Storage Total Enhancements
  • Loading branch information
kennethdsheridan authored Nov 8, 2024
2 parents 7d8c3bc + 99ca9c9 commit 36df79a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Binary file modified build/release/hardware_report-linux-x86_64
Binary file not shown.
35 changes: 35 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct SystemSummary {
memory_config: String,
/// Total storage capacity
total_storage: String,
/// Total storage capacity in TB
total_storage_tb: f64,
/// Available filesystems
filesystems: Vec<String>,
/// BIOS information
Expand Down Expand Up @@ -306,6 +308,31 @@ impl ServerInfo {

Ok(missing_packages)
}

/// Converts storage size string to bytes
fn parse_storage_size(size: &str) -> Result<u64, Box<dyn Error>> {
let size_str = size.replace(" ", "");
let re = Regex::new(r"(\d+(?:\.\d+)?)(B|K|M|G|T)")?;

if let Some(caps) = re.captures(&size_str) {
let value: f64 = caps[1].parse()?;
let unit = &caps[2];

let multiplier = match unit {
"B" => 1_u64,
"K" => 1024_u64,
"M" => 1024_u64 * 1024,
"G" => 1024_u64 * 1024 * 1024,
"T" => 1024_u64 * 1024 * 1024 * 1024,
_ => 0_u64,
};

Ok((value * multiplier as f64) as u64)
} else {
Err("Invalid storage size format".into())
}
}

/// Gets hostname of the server
fn get_hostname() -> Result<String, Box<dyn Error>> {
let output = Command::new("hostname").output()?;
Expand Down Expand Up @@ -787,9 +814,12 @@ impl ServerInfo {
if cpu_topology.numa_nodes > 1 { "s" } else { "" }
);

let total_storage_tb = Self::calculate_total_storage_tb(&hardware.storage)?;

Ok(SystemSummary {
total_memory: hardware.memory.total.clone(),
memory_config: format!("{} @ {}", hardware.memory.type_, hardware.memory.speed),
total_storage_tb,
total_storage: Self::calculate_total_storage(&hardware.storage)?,
filesystems: Self::get_filesystems().unwrap_or_default(),
bios,
Expand Down Expand Up @@ -1161,6 +1191,11 @@ fn main() -> Result<(), Box<dyn Error>> {
server_info.hardware.memory.speed
);

println!(
"Storage: {} (Total: {:.2} TB)",
server_info.summary.total_storage, server_info.summary.total_storage_tb
);

// Calculate total storage
let total_storage = server_info
.hardware
Expand Down

0 comments on commit 36df79a

Please sign in to comment.