简体中文
import { Sandbox } from 'ppio-sandbox/code-interpreter' const sandbox = await Sandbox.create() console.log('Sandbox created', sandbox.sandboxId) let metrics = await sandbox.getMetrics() // 您也可以通过指定沙箱 ID 来获取指标信息 // const metrics = await Sandbox.getMetrics(sandboxId) while (metrics && metrics.length <= 1) { console.log('Waiting for metrics...') await new Promise(resolve => setTimeout(resolve, 1000)) metrics = await sandbox.getMetrics() } console.log('Sandbox metrics:', metrics) await sandbox.kill() // 输出示例: // Sandbox metrics: [ // { // cpuCount: 2, // cpuUsedPct: 15.92, // memTotalMiB: 987, // memUsedMiB: 245, // timestamp: '2025-06-22T06:54:28.234Z' // }, // { // cpuCount: 2, // cpuUsedPct: 0.8, // memTotalMiB: 987, // memUsedMiB: 246, // timestamp: '2025-06-22T06:54:33.232Z' // } // ]
ppio-sandbox-cli sandbox metrics <sandbox_id>