diff --git a/build/release/hardware_report-linux-x86_64 b/build/release/hardware_report-linux-x86_64 index 9731642..99e7bb8 100755 Binary files a/build/release/hardware_report-linux-x86_64 and b/build/release/hardware_report-linux-x86_64 differ diff --git a/src/main.rs b/src/main.rs index d9ff0b9..6359263 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, /// BIOS information @@ -306,6 +308,31 @@ impl ServerInfo { Ok(missing_packages) } + + /// Converts storage size string to bytes + fn parse_storage_size(size: &str) -> Result> { + 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> { let output = Command::new("hostname").output()?; @@ -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, @@ -1161,6 +1191,11 @@ fn main() -> Result<(), Box> { 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