Expand description
§all-smi
A cross-platform library for monitoring GPU, NPU, CPU, and memory hardware.
all-smi provides a unified API for querying hardware metrics across multiple
platforms and device types including NVIDIA GPUs, AMD GPUs, Apple Silicon,
Intel Gaudi NPUs, Google TPUs, Tenstorrent, Rebellions, and Furiosa NPUs.
§Quick Start
use all_smi::{AllSmi, Result};
fn main() -> Result<()> {
// Initialize with auto-detection
let smi = AllSmi::new()?;
// Get all GPU/NPU information
for gpu in smi.get_gpu_info() {
println!("{}: {}% utilization, {:.1}W",
gpu.name, gpu.utilization, gpu.power_consumption);
}
// Get CPU information
for cpu in smi.get_cpu_info() {
println!("{}: {:.1}% utilization", cpu.cpu_model, cpu.utilization);
}
// Get memory information
for mem in smi.get_memory_info() {
println!("Memory: {:.1}% used", mem.utilization);
}
Ok(())
}§Using the Prelude
For convenience, you can import all common types with the prelude:
use all_smi::prelude::*;
fn main() -> Result<()> {
let smi = AllSmi::new()?;
let gpus: Vec<GpuInfo> = smi.get_gpu_info();
println!("Found {} GPU(s)", gpus.len());
Ok(())
}§Platform Support
| Platform | GPUs | NPUs | CPU | Memory |
|---|---|---|---|---|
| Linux | NVIDIA, AMD | Gaudi, TPU, Tenstorrent, Rebellions, Furiosa | Yes | Yes |
| macOS | Apple Silicon | - | Yes | Yes |
| Windows | NVIDIA, AMD | - | Yes | Yes |
§Features
- GPU Monitoring: Utilization, memory, temperature, power, frequency
- NPU Monitoring: Intel Gaudi, Google TPU, Tenstorrent, Rebellions, Furiosa
- CPU Monitoring: Utilization, frequency, temperature, P/E cores (Apple Silicon)
- Memory Monitoring: System RAM, swap, buffers, cache
- Process Monitoring: GPU processes with memory usage
- Chassis Monitoring: Total power, thermal pressure, fan speeds
Re-exports§
pub use client::AllSmi;pub use client::AllSmiConfig;pub use client::DeviceType;pub use error::Error;pub use error::Result;
Modules§
- app_
state - Application state management.
- cli
- Command-line interface definitions.
- client
- High-level client API for hardware monitoring. High-level client API for all-smi library.
- common
- Configuration module.
- device
- Device readers and types for GPU, CPU, memory monitoring.
- error
- Unified error types for the library. Unified error types for the all-smi library.
- network
- Network client for remote monitoring.
- parsing
- Parsing utilities and macros.
- prelude
- Prelude module for convenient imports. The all-smi prelude.
- storage
- Storage monitoring. Storage monitoring module.
- traits
- Common traits for collectors and exporters. Base traits for the all-smi refactoring
- ui
- Terminal UI components.
- utils
- Utility functions.
Macros§
- build_
detail_ map - Macro for building a detail HashMap with optional values
- cache_
device_ static_ info - Macro for initializing a static device cache with consistent error handling
- extract_
label_ to_ detail - Extract a label value from a HashMap and insert it into a detail HashMap with a given key. Useful for processing Prometheus label data.
- extract_
labels_ batch - Process multiple label extractions in a batch. Takes a list of label keys and inserts them into the detail map. Optimized to perform single HashMap lookup per key.
- extract_
struct_ fields - Extract fields from a struct and insert them into a HashMap. Useful for populating detail HashMaps from device structs. Optimized to avoid redundant allocations for static strings.
- get_
label_ or_ default - Extract a label value from a HashMap with a default if not present. Returns the value or a default. Uses efficient borrowing when possible.
- insert_
optional_ fields - Insert optional fields from a struct into a HashMap if they exist. Skips None values automatically. Optimized to avoid redundant allocations for static strings.
- parse_
colon_ value - Parse a value after a colon with optional type conversion. Simple utility for “Key: Value” parsing patterns.
- parse_
metric - Parse a numeric metric value from a “Key: Value
” line. - parse_
prefixed_ line - Parse a line starting with a specific prefix and extract the value. Useful for consistent prefix-based parsing.
- parse_
prometheus - Parse a Prometheus-formatted metric line using a regex with 3 capture groups:
- skip_
in_ ci - Helper macro to skip tests in CI environment
- skip_
without_ sudo - Helper macro to skip tests that require sudo privileges
- update_
metric_ field - Update a struct field based on a metric name match. Reduces repetitive match arms to single macro calls. Uses saturating casts to prevent overflow/underflow.
- update_
optional_ field - Update a field within an optional struct field. Useful for updating fields in optional nested structures like apple_silicon_info.