Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics methods to SDKs #543

Merged
merged 54 commits into from
Jan 24, 2025
Merged

Add metrics methods to SDKs #543

merged 54 commits into from
Jan 24, 2025

Conversation

0div
Copy link
Contributor

@0div 0div commented Jan 17, 2025

Description

Consolidate the branches from #523, #524 & #525

This relates to E2B-1311

Test

[js-sdk] pnpm test metrics
[python-sdk] poetry run pytest -n 4 --verbose -x -k "test_metrics"`

Usage

js-sdk

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

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

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' }

Copy link

linear bot commented Jan 17, 2025

Copy link

changeset-bot bot commented Jan 17, 2025

⚠️ No Changeset found

Latest commit: d920f54

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

# Description 
- [x] nextjs integration test template
- [x] `pnpm test:integration`
- [x] set of stress tests
- [x] adapt vitest workspace
@ValentaTomas ValentaTomas added the feature New feature or request label Jan 18, 2025
Copy link
Member

@jakubno jakubno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last few small NITs 🙏🏻

packages/cli/src/commands/sandbox/metrics.ts Outdated Show resolved Hide resolved
packages/js-sdk/src/sandbox/index.ts Outdated Show resolved Hide resolved
packages/js-sdk/tests/sandbox/metrics.test.ts Outdated Show resolved Hide resolved
packages/python-sdk/e2b/sandbox_async/main.py Outdated Show resolved Hide resolved
packages/python-sdk/e2b/sandbox_sync/main.py Outdated Show resolved Hide resolved
packages/python-sdk/e2b/sandbox_async/main.py Outdated Show resolved Hide resolved
packages/python-sdk/e2b/sandbox_sync/main.py Outdated Show resolved Hide resolved
Copy link
Member

@jakubno jakubno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

packages/js-sdk/src/sandbox/sandboxApi.ts Outdated Show resolved Hide resolved
@jakubno jakubno changed the base branch from main to beta January 23, 2025 23:34
@jakubno jakubno requested a review from mlejva as a code owner January 23, 2025 23:34
Co-authored-by: Jakub Novák <jakub@e2b.dev>
@0div
Copy link
Contributor Author

0div commented Jan 23, 2025

gonna try the stress test with 400 sanboxes on my 96 core to see how it behaves

@mlejva
Copy link
Member

mlejva commented Jan 23, 2025

Can you pls share a code snippet showing the usage from SDK (or update the PR's description)? I'm interested in the methods that the users will be interacting with

EDIT: Ignore me, I'm checking the preview of docs
EDIT 2: It's missing docs

@mlejva mlejva requested review from mlejva and removed request for mlejva January 23, 2025 23:43
@0div 0div merged commit 4a1f253 into beta Jan 24, 2025
2 checks passed
@0div 0div deleted the add-metrics-methods-to-sdks branch January 24, 2025 06:03
0div added a commit that referenced this pull request Jan 25, 2025
This documents the new SDK method implemented
[here](#543)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants