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

Add Motherboard Info Collection and Storage Total Enhancements #4

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading