Hardware Report can be used as a library in your Rust projects.
Add to your Cargo.toml:
[dependencies]
hardware_report = { git = "https://github.com/sfcompute/hardware_report.git" }use hardware_report::create_service;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let service = create_service()?;
let report = service.collect_hardware_info().await?;
println!("CPU: {}", report.hardware.cpu.model);
println!("Memory: {}", report.hardware.memory.total);
println!("GPUs: {}", report.hardware.gpus.devices.len());
Ok(())
}The main report structure containing all collected hardware information.
pub struct HardwareReport {
pub hostname: String,
pub hardware: HardwareInfo,
pub network: NetworkInfo,
pub summary: Summary,
}pub struct CpuInfo {
pub model: String,
pub cores: u32,
pub threads: u32,
pub sockets: u32,
pub speed: String,
pub vendor: String,
pub architecture: String,
pub frequency_mhz: u32,
pub cache_l1d_kb: Option<u32>,
pub cache_l2_kb: Option<u32>,
pub cache_l3_kb: Option<u32>,
}pub struct MemoryInfo {
pub total: String,
pub type_: String,
pub speed: String,
pub modules: Vec<MemoryModule>,
}pub struct StorageDevice {
pub name: String,
pub device_type: StorageType, // Nvme, Ssd, Hdd
pub size: String,
pub size_bytes: u64,
pub model: String,
pub serial_number: Option<String>,
}pub struct GpuDevice {
pub index: u32,
pub name: String,
pub uuid: String,
pub memory: String,
pub memory_total_mb: u32,
pub vendor: String,
pub pci_id: String,
}pub struct NetworkInterface {
pub name: String,
pub mac: String,
pub ip: String,
pub speed: String,
pub mtu: Option<u32>,
pub link_state: Option<String>,
}use hardware_report::{create_service, create_service_with_config};
// Default configuration
let service = create_service()?;
// Custom configuration
let config = ServiceConfig {
timeout_seconds: 30,
collect_gpu: true,
collect_network: true,
};
let service = create_service_with_config(config)?;See the examples/ directory for complete usage examples:
examples/basic_usage.rs- Simple hardware collectionexamples/library_usage.rs- Library integration patternsexamples/custom_analysis.rs- Custom data processing