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 command to CLI #525

Closed
wants to merge 1 commit into from
Closed

Conversation

0div
Copy link
Contributor

@0div 0div commented Dec 30, 2024

No description provided.

Copy link

changeset-bot bot commented Dec 30, 2024

⚠️ No Changeset found

Latest commit: 198ac2e

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

Copy link

linear bot commented Dec 30, 2024

@ValentaTomas ValentaTomas added feature New feature or request cli Improvements or additions to CLI labels Jan 7, 2025
@0div 0div mentioned this pull request Jan 17, 2025
@0div 0div closed this Jan 17, 2025
@0div
Copy link
Contributor Author

0div commented Jan 17, 2025

consolidated here: #543

0div added a commit that referenced this pull request Jan 24, 2025
### 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' }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Improvements or additions to CLI feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants