msb-metrics is a separate binary that continuously exports sandbox CPU,
memory, disk, and network metrics to an OpenTelemetry-compatible backend.
Run one collector on each host alongside microsandbox.
For a one-time reading, use msb metrics.
To read metrics in application code, use
Sandbox::metrics().
How it works
All three interfaces read the same host-local registry and can run together. This page covers continuous export withmsb-metrics.
Setup
Install
msb-metrics is not included with the
main msb installer. Download it from the
latest release
and place it on your PATH.
Requirements
The collector reads the shared-memory registry directly:- Run it as the same Unix user as
msb. The registry is owner-only. - Use the same
$MSB_HOMEasmsb. If needed, pass--msb-home; the default is~/.microsandbox. - Run one collector per host. Each registry contains only that host’s sandboxes.
Quick start
1
Start the collector
- gRPC
- HTTP
Use port
4317 for most local collectors and sidecars.2
Run a sandbox
3
Check your backend
Metrics appear after the next collection and export intervals.
Backends
For production, use Grafana Alloy or another local collector as a forwarder. You can also export directly to a hosted backend. End-to-end setup walkthroughs live under Examples:Grafana Alloy
Forward metrics through a local Alloy process.
Grafana Cloud
Export directly to Grafana Cloud.
Prometheus
Use Prometheus’s native OTLP receiver.
OpenTelemetry Collector
Run a local OpenTelemetry Collector.
Datadog
Export through the Datadog Agent.
Metrics
Sandbox metrics
Metrics use themicrosandbox.* namespace. The table shows only the suffix.
Disk and network totals are gauges containing absolute cumulative values. Use
rate() in PromQL for throughput.
Attributes
Every datapoint identifies its source and sandbox.
Sandbox labels are also included by default. Disable all
labels with
--no-labels, or repeat --exclude-label-key <key> to omit
specific keys from metrics without removing them from the sandbox catalog.
Label lookup is best-effort. If the catalog is unavailable, the collector
exports that sample without labels and tries again on the next interval.
Labels in queries
Prometheus replaces dots in OpenTelemetry names with underscores. For example,user.id becomes user_id, and microsandbox.cpu.utilization becomes
microsandbox_cpu_utilization.
Restarts and stops
Disk and network totals reset when a sandbox restarts. PromQLrate() handles
these resets, though a brief negative interval can appear before the next
sample.
Stopped sandboxes stop producing samples, so their series become stale. A
crashed sandbox behaves the same way: readers retire its abandoned registry
entry on the next collection. See Sandbox metrics for
the underlying lifecycle behavior.
Operations
Collector health
The collector exports its own health metrics through the same OTLP pipeline.
All use the OTel scope
microsandbox-metrics-collector.
Exports are flowing
Outages and retries
Failed exports return to the front of the buffer and retry with capped exponential backoff, from--flush-interval up to 32 times that interval.
Oldest collections are dropped when the buffer fills. The collector reports
the loss through collector.collections.dropped and continues running.
Scaling
Collector memory grows with the number of active sandboxes and buffered collections. Lower--max-buffered to reduce memory use during backend
outages, at the cost of dropping samples sooner. Monitor
collector.collections.dropped when choosing a buffer size.
Shutdown
On SIGINT or SIGTERM, the collector stops collecting, exports buffered samples, closes the OTLP transport, and exits.--export-timeout bounds the final
export.
Troubleshooting
No sandboxes appear
No sandboxes appear
Confirm a sandbox is running and both processes use the same
$MSB_HOME.
Pass --msb-home explicitly if necessary. Use --log-level=debug to see
the registry name.The backend returns 401, 403, or 422
The backend returns 401, 403, or 422
Check authentication headers and the endpoint protocol. gRPC commonly
uses port
4317; HTTP needs the complete metrics URL expected by your
backend, often ending in /v1/metrics.Restarts create new series
Restarts create new series
Disable
--emit-run-id and --emit-pid to keep one series per sandbox
identity across restarts.Reference
Usemsb-metrics <command> --help to see the same options in your terminal.
msb-metrics otel
msb-metrics otel
Export metrics over OTLP.Connection
Attributes
Collection
msb-metrics stdout
msb-metrics stdout
Print one human-readable line per snapshot without an OTLP receiver.The output is intended for inspection, not production parsers.
Global flags
Global flags