@@ -344,6 +344,61 @@ public function containerExportStream($container)
344344 );
345345 }
346346
347+ /**
348+ * Returns a container’s resource usage statistics.
349+ *
350+ * This is a JSON API endpoint that resolves with a single stats info.
351+ *
352+ * If you want to monitor live stats events as they happen, you
353+ * should consider using `imageStatsStream()` instead.
354+ *
355+ * @param string $container container ID
356+ * @return PromiseInterface Promise<array> JSON stats
357+ * @link https://docs.docker.com/engine/api/v1.40/#operation/ContainerStats
358+ * @since 0.3.0 Available as of Docker Engine API v1.19 (Docker v1.7), use `containerStatsStream()` on legacy versions
359+ * @see self::containerStatsStream()
360+ */
361+ public function containerStats ($ container )
362+ {
363+ return $ this ->browser ->get (
364+ $ this ->uri ->expand (
365+ '/containers/{container}/stats{?stream} ' ,
366+ array (
367+ 'container ' => $ container ,
368+ 'stream ' => 0
369+ )
370+ )
371+ )->then (array ($ this ->parser , 'expectJson ' ));
372+ }
373+
374+ /**
375+ * Returns a live stream of a container’s resource usage statistics.
376+ *
377+ * The resulting stream will emit the following events:
378+ * - data: for *each* element in the stats stream
379+ * - error: once if an error occurs, will close() stream then
380+ * - close: once the stream ends (either finished or after "error")
381+ *
382+ * @param string $container container ID
383+ * @return ReadableStreamInterface JSON stats stream
384+ * @link https://docs.docker.com/engine/api/v1.40/#operation/ContainerStats
385+ * @since 0.3.0 Available as of Docker Engine API v1.17 (Docker v1.5)
386+ * @see self::containerStats()
387+ */
388+ public function containerStatsStream ($ container )
389+ {
390+ return $ this ->streamingParser ->parseJsonStream (
391+ $ this ->browser ->withOptions (array ('streaming ' => true ))->get (
392+ $ this ->uri ->expand (
393+ '/containers/{container}/stats ' ,
394+ array (
395+ 'container ' => $ container
396+ )
397+ )
398+ )
399+ );
400+ }
401+
347402 /**
348403 * Resize the TTY of container id
349404 *
0 commit comments