Crate hardware_query

Source
Expand description

§Hardware Query

The easiest way to get hardware information in Rust.

This crate provides a simple, cross-platform API for hardware detection and system monitoring. Whether you need a quick system overview or detailed hardware analysis, there’s an API tier for you.

§Quick Start (1 line of code)

Get a complete system overview with health status:

use hardware_query::SystemOverview;
 
let overview = SystemOverview::quick()?;
println!("{}", overview);  // Formatted system summary with health status

§Domain-Specific Presets (2-3 lines)

Get assessments tailored to your use case:

use hardware_query::HardwarePresets;

// For AI/ML applications
let ai_assessment = HardwarePresets::ai_assessment()?;
println!("AI Score: {}/100", ai_assessment.ai_score);
println!("Supported Frameworks: {:?}", ai_assessment.frameworks);

// For gaming applications  
let gaming_assessment = HardwarePresets::gaming_assessment()?;
println!("Gaming Score: {}/100", gaming_assessment.gaming_score);
println!("Recommended Settings: {}", gaming_assessment.recommended_settings);

// For development environments
let dev_assessment = HardwarePresets::developer_assessment()?;
println!("Build Performance: {:?}", dev_assessment.build_performance);

§Custom Queries (3-5 lines)

Build exactly the hardware query you need:

use hardware_query::HardwareQueryBuilder;

// Get basic system info
let basic_info = HardwareQueryBuilder::new()
    .with_basic()
    .cpu_and_memory()?;

// Get AI-focused hardware info
let ai_info = HardwareQueryBuilder::new()
    .with_ai_focused()
    .gpu_and_accelerators()?;

// Get everything for system monitoring
let monitoring_info = HardwareQueryBuilder::new()
    .with_monitoring()
    .all_hardware()?;

§Complete Hardware Analysis (Advanced)

For detailed hardware analysis and custom processing:

use hardware_query::HardwareInfo;

// Get complete system information
let hw_info = HardwareInfo::query()?;

// Access detailed CPU information
let cpu = hw_info.cpu();
println!("CPU: {} {} - {} cores, {} threads",
    cpu.vendor(),
    cpu.model_name(),
    cpu.physical_cores(),
    cpu.logical_cores()
);

// Check specific CPU features for optimization
if cpu.has_feature("avx2") && cpu.has_feature("fma") {
    println!("CPU optimized for SIMD operations");
}

// Analyze GPU capabilities for AI workloads
for gpu in hw_info.gpus() {
    println!("GPU: {} {} - {} GB VRAM", 
        gpu.vendor(), gpu.model_name(), gpu.memory_gb());
     
    if gpu.supports_cuda() {
        println!("  CUDA support available");
    }
    if gpu.supports_opencl() {
        println!("  OpenCL support available");
    }
}

// Check for specialized AI hardware
if !hw_info.npus().is_empty() {
    println!("AI accelerators found: {} NPUs", hw_info.npus().len());
}

// Memory analysis for performance optimization
let memory = hw_info.memory();
println!("Memory: {} GB total, {} GB available",
    memory.total_gb(),
    memory.available_gb()
);

// Storage performance characteristics
for storage in hw_info.storage() {
    println!("Storage: {} - {} GB ({})",
        storage.model(),
        storage.capacity_gb(),
        if storage.is_ssd() { "SSD" } else { "HDD" }
    );
}

§Monitoring and Real-time Updates

For applications that need continuous hardware monitoring:

#[cfg(feature = "monitoring")]
use hardware_query::{HardwareMonitor, MonitoringConfig};

let config = MonitoringConfig::new()
    .with_cpu_monitoring(true)
    .with_thermal_monitoring(true)
    .with_interval_ms(1000);

let mut monitor = HardwareMonitor::new(config);

monitor.start_monitoring(|event| {
    match event {
        hardware_query::MonitoringEvent::TemperatureAlert { component, temp } => {
            println!("Warning: {} temperature: {}°C", component, temp);
        }
        hardware_query::MonitoringEvent::CpuUsageHigh { usage } => {
            println!("High CPU usage: {}%", usage);
        }
        _ => {}
    }
})?;

§Feature Flags

  • Default: Basic hardware detection (CPU, Memory, GPU, Storage)
  • monitoring: Real-time monitoring capabilities, thermal sensors, power management
  • serde: Serialization/deserialization support (automatically enabled)

§Platform Support

  • Windows: Native WMI and Windows API support
  • Linux: Comprehensive /proc, /sys filesystem support
  • macOS: IOKit and system framework integration

All APIs work consistently across platforms, with graceful degradation when specific hardware isn’t available.

Re-exports§

pub use simple::SystemOverview;
pub use simple::SimpleCPU;
pub use simple::SimpleGPU;
pub use simple::SimpleStorage;
pub use simple::SystemHealth;
pub use simple::HealthStatus;
pub use simple::TemperatureStatus;
pub use simple::PowerStatus;
pub use builder::HardwareQueryBuilder;
pub use builder::CustomHardwareInfo;
pub use presets::HardwarePresets;
pub use presets::AIHardwareAssessment;
pub use presets::GamingHardwareAssessment;
pub use presets::DeveloperHardwareAssessment;
pub use presets::ServerHardwareAssessment;

Modules§

builder
Hardware query builder for customizable hardware information gathering
platform
presets
Hardware query presets for common use cases
simple
Simplified hardware query interface - Start here for easy hardware detection

Structs§

ARMHardwareInfo
ARM hardware information
BatteryInfo
Battery information
CPUInfo
CPU information and specifications
ContainerRuntime
Container runtime information
CoolingRecommendation
Cooling optimization recommendation
FPGAInfo
FPGA accelerator information
FanInfo
Fan information
GPUInfo
GPU information and specifications
HardwareInfo
Complete system hardware information
HardwareMonitor
Real-time hardware monitor
MemoryInfo
System memory information
MonitoringConfig
Hardware monitoring configuration
MonitoringStats
Monitoring statistics
NPUInfo
NPU information structure
NetworkInfo
Network interface information
PCIDevice
PCI device information
PowerInfo
Power consumption and thermal information
PowerOptimization
Power optimization recommendation
PowerProfile
Power consumption profile for the system
ResourceLimits
Resource limits imposed by virtualization
StorageInfo
Storage device information
TPUInfo
TPU information structure
ThermalInfo
System thermal information
ThermalSensor
Thermal sensor information
ThrottlingPrediction
Thermal throttling prediction
USBDevice
USB device information
VirtualizationInfo
Virtualization environment information

Enums§

ARMSystemType
ARM-based system type
BatteryStatus
Battery status
CPUFeature
CPU feature flags
CPUVendor
CPU vendor information
FPGAFamily
FPGA family/series information
FPGAInterface
FPGA interface type
FPGAVendor
FPGA vendor information
GPUType
GPU type classification
GPUVendor
GPU vendor information
HardwareQueryError
Error types that can occur during hardware querying
MemoryType
Memory type classification
MonitoringEvent
Hardware monitoring event
NPUArchitecture
NPU architecture information
NPUType
NPU type classification
NPUVendor
NPU vendor information
NetworkType
Network interface type
OptimizationCategory
Category of power optimization
PowerState
Current system power state
StorageType
Storage device type
TPUArchitecture
TPU generation and architecture
TPUConnectionType
TPU connection type
TPUVendor
TPU vendor information
ThrottlingRisk
Risk level for thermal throttling
ThrottlingSeverity
Severity of thermal throttling
VirtualizationType
Type of virtualization environment

Traits§

MonitoringCallback
Hardware monitoring callback trait

Type Aliases§

Result
Result type for hardware query operations