> ## Documentation Index
> Fetch the complete documentation index at: https://namespace.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Metrics

> Check the CPU, memory, I/O, and disk usage of a running Devbox.

Metrics show how hard a Devbox is working, for example whether a slow build is short on memory or waiting on disk.

> [!NOTE]
>
> Every Devbox comes with [Namespace Compute](https://namespace.so/docs/architecture/compute.md)'s built-in observability. The [`nsc` CLI](https://namespace.so/docs/reference/cli/installation) and the compute client in the TS SDK read it for any running Devbox.

## Read a Devbox's metrics

**1. Find the instance ID**

Compute tools need the Devbox's instance ID, which changes on every start, so look it up while it's running. In the CLI, use the ID from `devbox list`.

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
devbox list
nsc list --label devbox.id=DEVBOX_ID
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const devbox = await client.devboxes.get("my-devbox");
const instanceId = devbox.info.instanceId;
```

**2. Read the metrics**

The CLI shows live usage in your terminal. The TS SDK returns time series for the period you ask for.

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
nsc top INSTANCE_ID
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { timestampFromDate } from "@bufbuild/protobuf/wkt";
import { createComputeClient } from "@namespacelabs/sdk/api/compute";
import {
  GetInstanceMetricsRequest_MetricResource as Metric,
} from "@namespacelabs/sdk/proto/namespace/cloud/compute/v1beta/compute_pb";

const compute = createComputeClient();
const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);

const { timeSeries } = await compute.compute.getInstanceMetrics({
  instanceId,
  startTimestamp: timestampFromDate(oneHourAgo),
  metricResource: [Metric.CPU, Metric.MEMORY],
});
```

## Available metrics

| Resource | Metrics |
| - | - |
| `CPU` | `cpu_max`, the busiest CPU, and `cpu_avg`, the average of all CPUs (0–100%) |
| `CPU_BREAKDOWN` | `cpu_0`, `cpu_1`, and so on, one per CPU (0–100%) |
| `IO_WAIT` | `io_wait_max` and `io_wait_avg`, the time CPUs spend waiting on disk (0–100%) |
| `MEMORY` | `mem_used` and `mem_available`, in bytes |
| `STORAGE` | `storage_used_percent_/` for the root disk, plus one per cache volume (0–100%) |

## Count running Devboxes across your account

If you build on the Namespace platform, the `namespace.account.running_instances` [OpenTelemetry metric](https://namespace.so/docs/platform/metrics.md) counts your running instances by purpose. Devboxes have the purpose `devbox`. Devboxes that are starting, stopped, or shutting down aren't counted.

## Related

* [Logs](https://namespace.so/docs/devbox/logs.md) to see what a Devbox printed.
* Reference: [`nsc top`](https://namespace.so/docs/reference/cli/top), [`getInstanceMetrics()`](https://namespace.so/docs/reference/typescript-sdk/compute/observability#compute-getinstancemetrics-api-reference).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.