Skip to main content
Query resource usage for a running sandbox: CPU, memory, and more. Get a single point-in-time snapshot, or open a streaming subscription that delivers updates at a fixed interval.

Point-in-time

use microsandbox::Sandbox;

let metrics = sb.metrics().await?;
println!("CPU: {:.1}%, Mem: {} MB", metrics.cpu_percent, metrics.memory_bytes / 1024 / 1024);

Streaming

Subscribe to metric updates at a regular interval. Each update arrives as a separate event.
use std::time::Duration;
use futures::StreamExt;

let mut stream = sb.metrics_stream(Duration::from_secs(1));
while let Some(m) = stream.next().await {
    let m = m?;
    println!("CPU: {:.1}%, Mem: {} MB", m.cpu_percent, m.memory_bytes / 1024 / 1024);
}

Fleet-wide metrics

Get metrics for all running sandboxes at once. Useful for dashboards or capacity planning.
use microsandbox::all_sandbox_metrics;

let all = all_sandbox_metrics().await?;