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

# Sandbox 指标

Sandbox 指标提供 Sandbox 带时间戳的 CPU、内存和磁盘使用率数据。

## 获取 Sandbox 指标

调用指标 API 会返回一组带时间戳的指标记录。指标每 5 秒采样一次。

### 使用 SDK 获取 Sandbox 指标

<CodeGroup>
  ```python Python theme={null}
  from time import sleep
  from ppio_sandbox import PPIO

  ppio = PPIO()

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

  # 等待指标采集。
  sleep(10)

  metrics = sbx.get_metrics()

  # 也可以通过 ID 获取：
  # metrics = ppio.sandbox.get_metrics(sbx.sandbox_id)

  print('Metrics:', metrics)
  ```

  ```typescript JavaScript & TypeScript theme={null}
  import { PPIO } from 'ppio-sandbox'

  const ppio = new PPIO()

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

  // 等待指标采集。
  await new Promise((resolve) => setTimeout(resolve, 10_000))

  const metrics = await sbx.getMetrics()

  // 也可以通过 ID 获取：
  // const metrics = await ppio.sandbox.getMetrics(sbx.sandboxId)

  console.log('Metrics:', metrics)
  ```
</CodeGroup>

### 使用 CLI 获取 Sandbox 指标

```bash theme={null}
ppio sandbox metrics <sandboxID>

# 输出示例：
# Sandbox 的指标
#
# [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
```

使用 `--follow` 可以实时持续输出指标流:

```bash theme={null}
ppio sandbox metrics <sandboxID> --follow
```

使用 `--format json` 可以输出机器可读的指标数据:

```bash theme={null}
ppio sandbox metrics <sandboxID> --format json
```

Sandbox 创建后指标可能不会立即出现;在第一次采样之前,响应可能为空。
