Sandbox
Metrics
Monitor sandbox resources and network usage.
Overview
Lelantos exposes metrics for running sandboxes, allowing you to monitor CPU, memory, disk, and network usage. Use metrics to right-size your templates, detect resource pressure in long-running workloads, and track managed-proxy usage.
Retrieving Metrics
const metrics = await sandbox.getMetrics();
const latest = metrics.at(-1);
if (latest) {
console.log("CPU count:", latest.cpuCount);
console.log("Memory:", `${latest.memUsed} / ${latest.memTotal} bytes`);
console.log("Disk:", `${latest.diskUsed} / ${latest.diskTotal} bytes`);
console.log("Network up:", latest.bytesUp ?? "unavailable");
console.log("Managed proxy bytes:", latest.proxiedBytes ?? "none");
}Metrics Fields
| Field | Type | Description |
|---|---|---|
cpuCount | number | Number of vCPUs allocated to the sandbox. |
memUsed | number | Memory currently in use (bytes). |
memTotal | number | Total memory allocated (bytes). |
diskUsed | number | Disk space currently in use (bytes). |
diskTotal | number | Total disk space allocated (bytes). |
bytesUp | number | null | Cumulative guest egress/upload bytes for the session, when available. |
bytesDown | number | null | Cumulative guest ingress/download bytes for the session, when available. |
networkCounterSource | string | null | Provenance of the network counters, such as the sandbox netns and TAP device. |
proxiedBytes | number | null | Cumulative managed-proxy bytes for the session. This is the billing basis for managed proxy usage. |
proxyClass | string | null | Managed proxy class, such as residential or residential-premium. |
Example: Formatting Metrics
const metrics = await sandbox.getMetrics();
const latest = metrics.at(-1);
if (!latest) throw new Error("No metrics returned");
const memUsedMB = (latest.memUsed / 1024 / 1024).toFixed(1);
const memTotalMB = (latest.memTotal / 1024 / 1024).toFixed(1);
const diskUsedGB = (latest.diskUsed / 1024 / 1024 / 1024).toFixed(2);
const diskTotalGB = (latest.diskTotal / 1024 / 1024 / 1024).toFixed(2);
console.log(`CPU: ${latest.cpuCount} vCPU`);
console.log(`Memory: ${memUsedMB} MB / ${memTotalMB} MB`);
console.log(`Disk: ${diskUsedGB} GB / ${diskTotalGB} GB`);
if (latest.proxiedBytes != null) {
console.log(`Managed proxy: ${latest.proxiedBytes} bytes (${latest.proxyClass ?? "unknown"})`);
}Coming Soon
Real-time CPU usage percentage collection is currently under development. The cpuCount field reports the number of allocated vCPUs, but per-second CPU utilization metrics will be available in a future release.