Kibotos

Metrics

The E2B SDK's sandbox.getMetrics() and Sandbox.getMetrics(id) return CPU, memory, and disk samples for a sandbox, as on E2B. This page covers the two metrics endpoints, the fields of each sample, and how time ranges and buckets work.

Prerequisites

Without a store, both metrics endpoints return 501 with the capability name metrics.

Important

Metrics are for observation only and are not usage or billing data. Samples can be missing for some periods; see Notes.

Reading metrics

The following example reads the samples of a sandbox and prints the CPU and memory use of the most recent one:

const samples = await sandbox.getMetrics();
const latest = samples.at(-1);
console.log(latest?.cpuUsedPct, latest?.memUsed);

The SDK calls one of two endpoints:

RequestReturns
GET /sandboxes/{id}/metricsAn array of samples for one sandbox, bucketed by time. Accepts start and end, in Unix seconds
GET /sandboxes/metrics?sandbox_ids=...The most recent sample of each sandbox, keyed by sandbox ID. See Batch endpoint

Sample fields

FieldMeaning
cpuCountThe number of online CPUs in the guest
cpuUsedPctThe busy share of all CPUs between two consecutive samples, from 0 to 100
memTotal, memUsed, memCacheMemTotal, MemTotal minus MemAvailable, and Cached from the guest's /proc/meminfo, in bytes
diskTotal, diskUsedTotal capacity and used space (total minus available) of the guest's root file system /, in bytes
timestamp, timestampUnixThe start of the bucket, in UTC RFC 3339 and in Unix seconds

Time range and buckets

Sampling

  • The node samples each running sandbox every 5 seconds.
  • After a sandbox starts or resumes, samples begin with the second sampling, because the first one only establishes the CPU baseline.

Time range

  • Without start and end, the whole history of the sandbox within the retention period is returned.
  • If only one end is given, the other end is the start or end of the sandbox's history.
  • The end is no later than the current time, and the start is no earlier than the beginning of the retention period.
  • start and end must be non-negative integers. If start is later than end, the request returns 400.
  • Only buckets that have ended, at a time no later than the current time minus the query delay, are returned. Newer buckets are returned once their samples in the store are final, so samples from roughly the last 30 seconds are not returned yet. The deployment sets the query delay, 30 seconds by default; see E2B gateway configuration.

Bucket width

The bucket width depends on the query span, as in E2B:

SpanBucket width
Less than 1 hour5 seconds
Less than 6 hours30 seconds
Less than 12 hours1 minute
Less than 24 hours2 minutes
Less than 7 days5 minutes
7 days or more15 minutes
  • Each field of a bucket takes the maximum of the samples in that bucket, and the timestamp is the start of the bucket.
  • Only buckets in which all seven fields have values are returned.
  • The first and last buckets are both full buckets, so they may include samples just outside [start, end].

Pause, resume, and deletion

  • After a pause and resume, it is still the same series. Each resume starts a new Instance, and the gateway merges the samples of all Instances by sandbox.
  • There are no samples while the sandbox is paused.
  • After a sandbox is deleted, its metrics can still be queried within the retention period.

Missing sandboxes and empty results

  • A sandbox that does not exist, or that belongs to another deployment namespace, returns 404.
  • A sandbox that exists but has no samples yet returns [].
  • Unlike on E2B, a sandbox whose Platform's guest predates the sampling interface is not sampled by the node, and queries return [].

Batch endpoint

GET /sandboxes/metrics returns the latest sample of several sandboxes in one request:

  • sandbox_ids is comma-separated, with at most 100 IDs and no duplicates. If it is missing or empty, the request returns 400.
  • Each sandbox returns its latest sample up to "current time minus query delay".
  • The latest sample is therefore usually 30 to 60 seconds old.
  • A sandbox with no sample in the 30 seconds before that moment does not appear in the result. Neither do sandboxes that do not exist or belong to other deployments. The request still returns 200.

Notes

  • When the store is unreachable, the guest does not respond in time, or the node restarts, samples for that period are missing.
  • When the store is unavailable, both endpoints return 500 with the message failed to fetch sandbox metrics.
  • Each gateway instance caches the query result for a single sandbox for 1 second.
  • Team metrics are not provided. See Not supported.

Next steps

On this page