Skip to main content

Crate all_smi

Crate all_smi 

Source
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

PlatformGPUsNPUsCPUMemory
LinuxNVIDIA, AMDGaudi, TPU, Tenstorrent, Rebellions, FuriosaYesYes
macOSApple Silicon-YesYes
WindowsNVIDIA, AMD-YesYes

§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.