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

# Sandbox-Metriken

Sandbox-Metriken stellen mit Zeitstempeln versehene Daten zur CPU-, Speicher- und Festplattenauslastung für eine Sandbox bereit.

## Sandbox-Metriken abrufen

Der Aufruf der Metrics-API gibt eine Liste von Metrikdatensätzen mit Zeitstempeln zurück. Metriken werden alle 5 Sekunden erfasst.

### Sandbox-Metriken mit den SDKs abrufen

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox'

  const sbx = await Sandbox.create()
  console.log('Created sandbox:', sbx.sandboxId)

  // Allow time for metrics collection.
  await new Promise((resolve) => setTimeout(resolve, 10_000))

  const metrics = await sbx.getMetrics()

  // Alternative by ID:
  // const metrics = await Sandbox.getMetrics(sbx.sandboxId)

  console.log('Metrics:', metrics)

  // Example shape:
  // [
  //   {
  //     timestamp: 2025-07-28T08:04:05.000Z,
  //     cpuUsedPct: 20.33,
  //     cpuCount: 2,
  //     memUsed: 32681984, // bytes
  //     memTotal: 507592704, // bytes
  //     diskUsed: 1514856448, // bytes
  //     diskTotal: 2573185024 // bytes
  //   },
  //   {
  //     timestamp: 2025-07-28T08:04:10.000Z,
  //     cpuUsedPct: 0.2,
  //     cpuCount: 2,
  //     memUsed: 33316864, // bytes
  //     memTotal: 507592704, // bytes
  //     diskUsed: 1514856448, // bytes
  //     diskTotal: 2573185024 // bytes
  //   }
  // ]
  ```

  ```python Python icon="python" theme={"system"}
  from time import sleep
  from novita_sandbox.core import Sandbox

  sbx = Sandbox.create()
  print('Created sandbox:', sbx.sandbox_id)

  # Allow time for metrics collection.
  sleep(10)

  metrics = sbx.get_metrics()

  # Alternative by ID:
  # metrics = Sandbox.get_metrics(sbx.sandbox_id)

  print('Metrics:', metrics)

  # Example shape:
  # [
  #     SandboxMetrics(
  #         cpu_count=2,
  #         cpu_used_pct=13.97,
  #         disk_total=2573185024,
  #         disk_used=1514856448,
  #         mem_total=507592704,
  #         mem_used=30588928,
  #         timestamp=datetime.datetime(2025, 7, 28, 8, 8, 15, tzinfo=tzutc()),
  #     ),
  #     SandboxMetrics(
  #         cpu_count=2,
  #         cpu_used_pct=0.1,
  #         disk_total=2573185024,
  #         disk_used=1514856448,
  #         mem_total=507592704,
  #         mem_used=31084544,
  #         timestamp=datetime.datetime(2025, 7, 28, 8, 8, 20, tzinfo=tzutc()),
  #     ),
  # ]
  ```
</CodeGroup>

### Sandbox-Metriken mit der CLI abrufen

```bash theme={"system"}
novita-sandbox-cli sandbox metrics <sandbox_id>

# Example output:
# Metrics for sandbox <sandbox_id>
#
# [2025-07-25 14:05:55Z] CPU: 8.27% / 2 Cores | Memory: 31 / 484 MiB | Disk: 1445 / 2453 MiB
# [2025-07-25 14:06:00Z] CPU: 0.5% / 2 Cores | Memory: 32 / 484 MiB | Disk: 1445 / 2453 MiB
# [2025-07-25 14:06:05Z] CPU: 0.1% / 2 Cores | Memory: 32 / 484 MiB | Disk: 1445 / 2453 MiB
# [2025-07-25 14:06:10Z] CPU: 0.3% / 2 Cores | Memory: 32 / 484 MiB | Disk: 1445 / 2453 MiB
```

Verwenden Sie `--follow`, um Metriken kontinuierlich in Echtzeit zu streamen:

```bash theme={"system"}
novita-sandbox-cli sandbox metrics <sandbox_id> --follow
```

Verwenden Sie `--format json`, um maschinenlesbare Metriken auszugeben:

```bash theme={"system"}
novita-sandbox-cli sandbox metrics <sandbox_id> --format json
```

<Note>
  Metriken werden möglicherweise nicht unmittelbar nach der Erstellung der Sandbox angezeigt; vor der ersten Erfassung kann die Antwort leer sein.
</Note>
