Metrics
Read a microVM's CPU use over time and the memory and disk it uses right now, from the console, the SDK, the CLI or the API.
Use metrics to see how hard a microVM works and how full it is. They return the microVM's CPU use over a recent window and, while it runs, the memory and disk it uses at that moment.
Read metrics
In the console, open the microVM: its Usage card shows the CPU chart and the memory and disk meters, and refreshes every 10 seconds.
import { MicroVM } from '@gigadrive/sdk';
const vm = await MicroVM.get('0199a7c4-5b1e-7c3d-9f20-333333333333');
const { cpu, current } = await vm.getMetrics({ windowMinutes: 60 });
const peak = Math.max(0, ...cpu.map((point) => point.cpuPercent));
console.log(`Peak CPU in the last hour: ${peak.toFixed(1)}%`);
if (current) console.log(`Memory: ${current.memoryUsedBytes} of ${current.memoryTotalBytes} bytes`);client.microvms.getMetrics(id, options) returns the same result when you only have the ID.
windowMinutes sets how far back the CPU series reaches: 1 to 1440 minutes, 15 by default. Reading metrics needs the network:microvms:read scope and never resumes a paused microVM.
The response
| Field | Meaning |
|---|---|
vcpus | vCPUs the microVM has |
memoryMb | Memory the microVM has, in MB |
windowMinutes | The window the CPU series covers |
stepSeconds | Length of each CPU point, at least 5 seconds |
cpu | Points of { time, cpuPercent }, oldest first |
current | Memory and disk in use now, or null when the microVM did not report them |
cpuPercent is the CPU the microVM used during the point, as a share of all its vCPUs, from 0 to 100. A microVM with 2 vCPUs that keeps one of them busy shows 50. The series holds at most 180 points, so a longer window gets longer points. Points when the microVM was not running are left out, so a gap in the series is time it was paused or stopped.
current holds memoryUsedBytes, memoryTotalBytes, diskUsedBytes, diskTotalBytes, uptimeMs and sampledAt. The microVM reports these itself: memory in use is its total memory minus what it still has available, and disk in use is the space taken on its disk. current is null when the microVM is not running, or when it did not answer within 3 seconds; read the metrics again a moment later.
Related
- Webhooks tell you when a microVM starts, pauses, stops or fails.
- Limits and pricing lists the vCPU, memory and disk sizes you can create.
