-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Description Consolidate the branches from #523, #524 & #525 This relates to [E2B-1311](https://linear.app/e2b/issue/E2B-1311/add-metrics-method-to-sandbox-to-sdks-that-returns-captured-metrics) ### Test `[js-sdk] pnpm test metrics` `[python-sdk]` poetry run pytest -n 4 --verbose -x -k "test_metrics"` ### Usage #### js-sdk ```js import { Sandbox } from '@e2b/code-interpreter' const sbx = await Sandbox.create() console.log('Sandbox created', sbx.sandboxId) const metrics = await sbx.getMetrics() console.log('Sandbox metrics:', metrics) /* [ { cpuCount: 2, cpuPct: 50.05, memTotalMiB: 484, memUsedMiB: 37, timestamp: '2025-01-23T23:44:12.222Z' }, { cpuCount: 2, cpuPct: 4.5, memTotalMiB: 484, memUsedMiB: 37, timestamp: '2025-01-23T23:44:13.220Z' } ] */ ``` #### python-sdk ```py from e2b_code_interpreter import Sandbox sbx = Sandbox() print('Sandbox created', sbx.sandbox_id) metrics = sbx.get_metrics() print('Sandbox metrics', metrics) # [ # SandboxMetrics(timestamp=datetime.datetime(2025, 1, 23, 23, 58, 42, 84050, tzinfo=tzutc()), cpu_pct=50.07, cpu_count=2, mem_used_mib=37, mem_total_mib=484), # SandboxMetrics(timestamp=datetime.datetime(2025, 1, 23, 23, 58, 44, 84845, tzinfo=tzutc()), cpu_pct=4.75, cpu_count=2, mem_used_mib=38, mem_total_mib=484), # ] ``` #### cli ```sh jonas@mac cli % pnpm build jonas@mac cli % E2B_DOMAIN=goulash.dev ./dist/index.js sbx sp jonas@mac cli % E2B_DOMAIN=goulash.dev ./dist/index.js sbx metrics {sandbox_id} Metrics for sandbox {sandbox_id} [2025-01-23 00:58:58.829Z] { cpuCount: 2, cpuPct: 50.21, logger: '', memTotalMiB: 484, memUsedMiB: 38, timestamp: '2025-01-23T00:58:58.829638869Z' } [2025-01-23 00:59:03.814Z] { cpuCount: 2, cpuPct: 5.16, logger: '', memTotalMiB: 484, memUsedMiB: 37, timestamp: '2025-01-23T00:59:03.814028031Z' } [2025-01-23 00:59:08.815Z] { cpuCount: 2, cpuPct: 1.6, logger: '', memTotalMiB: 484, memUsedMiB: 37, timestamp: '2025-01-23T00:59:08.815933749Z' } ```
- Loading branch information
Showing
40 changed files
with
1,305 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.