@@ -125,6 +125,47 @@ export interface ListedSandbox {
125125}
126126
127127
128+ /**
129+ * Sandbox resource usage metrics.
130+ */
131+ export interface SandboxMetrics {
132+ /**
133+ * Timestamp of the metrics.
134+ */
135+ timestamp : Date
136+
137+ /**
138+ * CPU usage in percentage.
139+ */
140+ cpuUsedPct : number
141+
142+ /**
143+ * Number of CPU cores.
144+ */
145+ cpuCount : number
146+
147+ /**
148+ * Memory usage in bytes.
149+ */
150+ memUsed : number
151+
152+ /**
153+ * Total memory available in bytes.
154+ */
155+ memTotal : number
156+
157+ /**
158+ * Used disk space in bytes.
159+ */
160+ diskUsed : number
161+
162+ /**
163+ * Total disk space available in bytes.
164+ */
165+ diskTotal : number
166+ }
167+
168+
128169export class SandboxApi {
129170 protected constructor ( ) { }
130171
@@ -262,6 +303,49 @@ export class SandboxApi {
262303 }
263304 }
264305
306+
307+ /**
308+ * Get the metrics of the sandbox.
309+ *
310+ * @param sandboxId sandbox ID.
311+ * @param opts connection options.
312+ *
313+ * @returns metrics of the sandbox.
314+ */
315+ static async getMetrics (
316+ sandboxId : string ,
317+ opts ?: SandboxApiOpts
318+ ) : Promise < SandboxMetrics [ ] > {
319+ const config = new ConnectionConfig ( opts )
320+ const client = new ApiClient ( config )
321+
322+ const res = await client . api . GET ( '/sandboxes/{sandboxID}/metrics' , {
323+ params : {
324+ path : {
325+ sandboxID : sandboxId ,
326+ } ,
327+ } ,
328+ signal : config . getSignal ( opts ?. requestTimeoutMs ) ,
329+ } )
330+
331+ const err = handleApiError ( res )
332+ if ( err ) {
333+ throw err
334+ }
335+
336+ return (
337+ res . data ?. map ( ( metric : components [ 'schemas' ] [ 'SandboxMetric' ] ) => ( {
338+ timestamp : new Date ( metric . timestamp ) ,
339+ cpuUsedPct : metric . cpuUsedPct ,
340+ cpuCount : metric . cpuCount ,
341+ memUsed : metric . memUsed ,
342+ memTotal : metric . memTotal ,
343+ diskUsed : metric . diskUsed ,
344+ diskTotal : metric . diskTotal ,
345+ } ) ) ?? [ ]
346+ )
347+ }
348+
265349 /**
266350 * Set the timeout of the specified sandbox.
267351 * After the timeout expires the sandbox will be automatically killed.
0 commit comments