From 062c6cab42e4b4873154d964c002983a3370d753 Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 24 Jan 2025 11:52:19 -0800 Subject: [PATCH 1/7] add metrics docs page --- .../app/(docs)/docs/sandbox/metrics/page.mdx | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx diff --git a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx new file mode 100644 index 000000000..19c9531e7 --- /dev/null +++ b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx @@ -0,0 +1,118 @@ +# Sandbox metrics + + +Sandbox metrics is currently in beta: +1. [Reach out to us](/docs/support) with your use case to get access to the beta. +1. You'll need to install the [beta version of the SDKs](#installing-the-beta-version-of-the-sdks). +1. Consider [some limitations](#limitations-while-in-beta). +1. Metrics is free for all users during the beta. + + +The sandbox metrics allows you to get information about the sandbox's CPU and memory usage. + +## 1. Installing the beta version of the SDKs +To get sandbox metrics, you need to install the beta version of the SDKs. + + +```bash {{ language: 'js' }} +npm i @e2b/code-interpreter@beta +# +# or use Core: https://github.com/e2b-dev/e2b +# npm i e2b@beta +# +# or use Desktop: https://github.com/e2b-dev/desktop +# npm i @e2b/desktop@beta +``` + +```bash {{ language: 'python' }} +pip install e2b-code-interpreter==1.0.4b +# +# or use Core: https://github.com/e2b-dev/e2b +# pip install e2b==1.1.0.b +# +# or use Desktop: https://github.com/e2b-dev/desktop +# pip install e2b-desktop==1.1.0.b +``` + + + +## 2. Getting sandbox metrics +Getting the metrics of a sandbox returns an array of timestamped metrics containing CPU and memory usage information. +The metrics are collected at the start of the sandbox, then every 2 seconds, and finally right before the sandbox is deleted. + + +```js +import { Sandbox } from '@e2b/code-interpreter' + +const sbx = await Sandbox.create() +console.log('Sandbox created', sbx.sandboxId) + +const metrics = await sbx.getMetrics() // $HighlightLine + +// You can also get the metrics by sandbox ID: +// const metrics = await Sandbox.getMetrics(sbx.sandboxId) + +console.log('Sandbox metrics:', metrics) + +// [ +// { +// cpuCount: 2, +// cpuUsedPct: 50.05, +// memTotalMiB: 484, +// memUsedMiB: 37, +// timestamp: '2025-01-23T23:44:12.222Z' +// }, +// { +// cpuCount: 2, +// cpuUsedPct: 4.5, +// memTotalMiB: 484, +// memUsedMiB: 37, +// timestamp: '2025-01-23T23:44:13.220Z' +// } +// ] + +``` +```python +from e2b_code_interpreter import Sandbox + +sbx = Sandbox() +print('Sandbox created', sbx.sandbox_id) + +metrics = sbx.get_metrics() # $HighlightLine + +# You can also get the metrics by sandbox ID: +# metrics = Sandbox.get_metrics(sbx.sandbox_id) + +print('Sandbox metrics', metrics) + +# [ +# SandboxMetrics(timestamp=datetime.datetime( +# 2025, 1, 23, 23, 58, 42, 84050, tzinfo=tzutc()), +# cpu_count=2, +# cpu_used_pct=50.07, +# mem_total_mib=484 +# mem_used_mib=37, +# ), +# SandboxMetrics(timestamp=datetime.datetime( +# 2025, 1, 23, 23, 58, 44, 84845, tzinfo=tzutc()), +# cpu_count=2, +# cpu_used_pct=4.75, +# mem_total_mib=484 +# mem_used_mib=38, +# ), +# ] +``` +```bash +e2b sandbox metrics # $HighlightLine + +# Metrics for sandbox +# +# [2025-01-23 00:58:58.829Z] { cpuCount: 2, cpuUsedPct: 50.21, logger: '', memTotalMiB: 484, memUsedMiB: 38, timestamp: '2025-01-23T00:58:58.829638869Z' } +# [2025-01-23 00:59:03.814Z] { cpuCount: 2, cpuUsedPct: 5.16, logger: '', memTotalMiB: 484, memUsedMiB: 37, timestamp: '2025-01-23T00:59:03.814028031Z' } +# [2025-01-23 00:59:08.815Z] { cpuCount: 2, cpuUsedPct: 1.6, logger: '', memTotalMiB: 484, memUsedMiB: 37, timestamp: '2025-01-23T00:59:08.815933749Z' } +``` + + +## Limitations while in beta +- It takes a few seconds to get the metrics after the sandbox is created. +- We are currently returning virtual memory usage. From c4a54fccc7995f88e5751c28e9653cbbeaddf87d Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 24 Jan 2025 11:59:18 -0800 Subject: [PATCH 2/7] add metrics to routes --- apps/web/src/components/Navigation/routes.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/web/src/components/Navigation/routes.tsx b/apps/web/src/components/Navigation/routes.tsx index e5ce63c71..b4aeaf38d 100644 --- a/apps/web/src/components/Navigation/routes.tsx +++ b/apps/web/src/components/Navigation/routes.tsx @@ -280,6 +280,11 @@ export const docRoutes: NavGroup[] = [ tag: Tag.New, href: '/docs/sandbox/persistence', }, + { + title: 'Metrics', + tag: Tag.New, + href: '/docs/sandbox/metrics', + }, { title: 'Metadata', href: '/docs/sandbox/metadata', From 44506801e883a1225fb0e713b272afb822e140a6 Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 24 Jan 2025 13:45:27 -0800 Subject: [PATCH 3/7] update docs based on feedback --- .../app/(docs)/docs/sandbox/metrics/page.mdx | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx index 19c9531e7..21ce9e612 100644 --- a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx +++ b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx @@ -10,31 +10,28 @@ Sandbox metrics is currently in beta: The sandbox metrics allows you to get information about the sandbox's CPU and memory usage. -## 1. Installing the beta version of the SDKs -To get sandbox metrics, you need to install the beta version of the SDKs. +## 1. Installing the beta version of the SDKs and CLI +To get sandbox metrics, you need to install the beta version of the SDKs and CLI. - + ```bash {{ language: 'js' }} -npm i @e2b/code-interpreter@beta +npm i @e2b/code-interpreter@beta1.2.0-beta.0 # # or use Core: https://github.com/e2b-dev/e2b -# npm i e2b@beta -# -# or use Desktop: https://github.com/e2b-dev/desktop -# npm i @e2b/desktop@beta +# npm i e2b@1.2.0-beta.0 ``` ```bash {{ language: 'python' }} -pip install e2b-code-interpreter==1.0.4b +pip install e2b-code-interpreter==1.2.0b0 # # or use Core: https://github.com/e2b-dev/e2b -# pip install e2b==1.1.0.b -# -# or use Desktop: https://github.com/e2b-dev/desktop -# pip install e2b-desktop==1.1.0.b +# pip install e2b==1.2.0b0 ``` - +```bash {{ language: 'bash' }} +npm i -g @e2b/cli@1.2.0-beta.0 +``` + ## 2. Getting sandbox metrics Getting the metrics of a sandbox returns an array of timestamped metrics containing CPU and memory usage information. @@ -98,10 +95,12 @@ print('Sandbox metrics', metrics) # cpu_count=2, # cpu_used_pct=4.75, # mem_total_mib=484 -# mem_used_mib=38, +# mem_used_mib=38, # ), # ] ``` + + ```bash e2b sandbox metrics # $HighlightLine @@ -114,5 +113,5 @@ e2b sandbox metrics # $HighlightLine ## Limitations while in beta -- It takes a few seconds to get the metrics after the sandbox is created. -- We are currently returning virtual memory usage. +- It takes a few seconds to get the metrics after the sandbox is created, because the logs are collected from the sandbox. +- We are currently returning virtual memory usage, this is a commonly used metric but it doesn't reflect real-time memory consumption or direct hardware resource allocation, because the OS can swap data between RAM and disk. From 295f4e2443ed14faa013b85ae4b82ad02d01ebf6 Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 24 Jan 2025 13:55:00 -0800 Subject: [PATCH 4/7] fix code snippet and remove note --- .../app/(docs)/docs/sandbox/metrics/page.mdx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx index 21ce9e612..aa1607ede 100644 --- a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx +++ b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx @@ -1,18 +1,13 @@ # Sandbox metrics - -Sandbox metrics is currently in beta: -1. [Reach out to us](/docs/support) with your use case to get access to the beta. -1. You'll need to install the [beta version of the SDKs](#installing-the-beta-version-of-the-sdks). -1. Consider [some limitations](#limitations-while-in-beta). -1. Metrics is free for all users during the beta. - - The sandbox metrics allows you to get information about the sandbox's CPU and memory usage. -## 1. Installing the beta version of the SDKs and CLI +## 1. Installation + To get sandbox metrics, you need to install the beta version of the SDKs and CLI. +### 1.1. Installing the beta version of the SDKs + ```bash {{ language: 'js' }} npm i @e2b/code-interpreter@beta1.2.0-beta.0 @@ -27,7 +22,11 @@ pip install e2b-code-interpreter==1.2.0b0 # or use Core: https://github.com/e2b-dev/e2b # pip install e2b==1.2.0b0 ``` + +### 1.2. Installing the beta version of the CLI + + ```bash {{ language: 'bash' }} npm i -g @e2b/cli@1.2.0-beta.0 ``` @@ -37,6 +36,8 @@ npm i -g @e2b/cli@1.2.0-beta.0 Getting the metrics of a sandbox returns an array of timestamped metrics containing CPU and memory usage information. The metrics are collected at the start of the sandbox, then every 2 seconds, and finally right before the sandbox is deleted. +### 2.1. Getting sandbox metrics using the SDKs + ```js import { Sandbox } from '@e2b/code-interpreter' @@ -100,6 +101,8 @@ print('Sandbox metrics', metrics) # ] ``` + +### 2.2. Getting sandbox metrics using the CLI ```bash e2b sandbox metrics # $HighlightLine From 974d92e7aae71b5d57c782645faa5c9579479d47 Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 24 Jan 2025 16:24:25 -0800 Subject: [PATCH 5/7] update limitations section --- apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx index aa1607ede..0fb6d8904 100644 --- a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx +++ b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx @@ -116,5 +116,4 @@ e2b sandbox metrics # $HighlightLine ## Limitations while in beta -- It takes a few seconds to get the metrics after the sandbox is created, because the logs are collected from the sandbox. -- We are currently returning virtual memory usage, this is a commonly used metric but it doesn't reflect real-time memory consumption or direct hardware resource allocation, because the OS can swap data between RAM and disk. +- It may take a second or more to get the metrics after the sandbox is created. Until the logs are collected from the sandbox, you will get an empty array. \ No newline at end of file From 61c7bfa7677d95402232aa71263d7e16b8b77b51 Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 24 Jan 2025 16:39:37 -0800 Subject: [PATCH 6/7] fix beta version typo and add private beta note --- apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx index 0fb6d8904..784dc3eac 100644 --- a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx +++ b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx @@ -1,5 +1,9 @@ # Sandbox metrics + +This feature is in a private beta. + + The sandbox metrics allows you to get information about the sandbox's CPU and memory usage. ## 1. Installation @@ -10,7 +14,7 @@ To get sandbox metrics, you need to install the beta version of the SDKs and CLI ```bash {{ language: 'js' }} -npm i @e2b/code-interpreter@beta1.2.0-beta.0 +npm i @e2b/code-interpreter@1.2.0-beta.0 # # or use Core: https://github.com/e2b-dev/e2b # npm i e2b@1.2.0-beta.0 From 35c18374d3d885a63974be68f184e655ba9b2fc9 Mon Sep 17 00:00:00 2001 From: 0div Date: Fri, 24 Jan 2025 16:46:48 -0800 Subject: [PATCH 7/7] use latest beta tag for npm installs --- apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx index 784dc3eac..99b7487c9 100644 --- a/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx +++ b/apps/web/src/app/(docs)/docs/sandbox/metrics/page.mdx @@ -14,10 +14,10 @@ To get sandbox metrics, you need to install the beta version of the SDKs and CLI ```bash {{ language: 'js' }} -npm i @e2b/code-interpreter@1.2.0-beta.0 +npm i @e2b/code-interpreter@beta # # or use Core: https://github.com/e2b-dev/e2b -# npm i e2b@1.2.0-beta.0 +# npm i e2b@beta ``` ```bash {{ language: 'python' }} @@ -32,7 +32,7 @@ pip install e2b-code-interpreter==1.2.0b0 ```bash {{ language: 'bash' }} -npm i -g @e2b/cli@1.2.0-beta.0 +npm i -g @e2b/cli@beta ```