feat(daemon,sdk): live sandbox resource metrics#5114
Open
MDzaja wants to merge 1 commit into
Open
Conversation
|
View your CI Pipeline Execution ↗ for commit c58dbe5
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
4 issues found across 59 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
Signed-off-by: MDzaja <mirkodzaja0@gmail.com>
29e3896 to
c58dbe5
Compare
2c15a7f to
b40f732
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a live resource-usage snapshot for sandboxes. A new daemon endpoint
GET /system/metricsreturns current CPU, memory and disk usage, surfaced through all five SDKs assandbox.getMetrics()(Python sync + async, TypeScript, Go, Ruby, Java).Motivation
There's currently no first-class way for an SDK caller to read a sandbox's live resource usage. This exposes it directly from the sandbox daemon, so applications can monitor CPU/memory/disk, drive autoscaling decisions, or surface usage in dashboards.
What it returns
SystemMetrics:timestamptimestampUnixcpuCountceil(cpuLimit))cpuUsedPctmemUsedmemTotalmemCachediskUseddiskTotaldiskFreeHow it works
0until the first sample window completes (cold start), and resets to0on a counter reset (cgroup recreated) or a backwards clock.memory.current/memory.statandstatfs), so they're always fresh.Changes by component
Daemon (Go)
apps/daemon/pkg/toolbox/system/package: theSystemMetricsDTO, the background sampler, and theGET /system/metricshandler.server.go: starts the sampler and registers the route.format:"int64"(andcpuUsedPctformat:"double") so strongly-typed generated clients use 64-bit types instead of overflow-prone 32-bit ones.Shared telemetry (
libs/common-go/pkg/telemetry)GetContainerLimits,GetDiskStats,ReadCgroupMemUsageBytes,ReadCgroupMemCacheBytes,ReadCgroupCPUUsageNanos) and a sharedCPUUsagePercentformula.Generated API clients (all languages)
SystemApi.getSystemMetrics()+SystemMetricsmodel.SDKs (all five)
getMetrics()method on the sandbox, returning the liveSystemMetrics. Mirrors the existing toolbox-API wiring (e.g. the info API) and is purely additive.Backward compatibility
SystemMetricsmodel, and new SDK methods. No existing request/response contract, DTO, or SDK signature changed.getMetrics()requires the new daemon; against an older daemon the endpoint simply 404s.Testing
-race.memUsed ≤ memTotal,diskUsed ≤ diskTotal,cpuCount ≥ 1, etc.).Safety / performance notes
Field-semantics notes (for API docs / consumers)
memUsedalready includes page cache, so don't addmemCacheon top of it.cpuCountisceil(cpuLimit), so a fractional CPU limit rounds up.diskUsed + diskFreemay be slightly less thandiskTotal(filesystem reserves blocks for root).Summary by cubic
Add live sandbox resource metrics via
GET /system/metricsandsandbox.getMetrics()/get_metrics()in all SDKs to read CPU, memory, and disk in real time. This enables monitoring, autoscaling, and dashboards.New Features
GET /system/metricsreturns a snapshot withtimestamp,timestampUnix,cpuCount,cpuUsedPct,memUsed,memTotal,memCache,diskUsed,diskTotal,diskFree. CPU% is averaged over a 5s background sampler; memory and disk are read on demand.SystemApi.getSystemMetrics()and aSystemMetricsmodel.CPUUsagePercent; the OTEL path reuses them. Unit and e2e tests validate formulas and bounds.Migration
sandbox.getMetrics()/get_metrics().Written for commit c58dbe5. Summary will update on new commits.