Skip to content

Commit f2b8d6c

Browse files
committed
Feature: new command to display containers resource stats
1 parent a4491da commit f2b8d6c

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Name | Details
5151
ws:sites |Display list of available sites and their statuses.
5252
ws:ssh |SSH into a container for a site within the workspace.
5353
ws:start |Create and start containers for a site within the workspace. A wrapper to docker-compose up.
54+
ws:stat |Display a live stream of container(s) resource usage statistics.
5455
ws:stop |Stop services for a site within the workspace. A wrapper to docker stop command.
5556
ws:update |Re-create local development site by updating the containers files, except for the directories site, env, solr/myindex.
5657

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/*
3+
* This file is part of the MooCommand package.
4+
*
5+
* (c) Mohamed Alsharaf <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace MooCommand\Command\Workspace;
12+
13+
use MooCommand\Command\Workspace as WorkspaceAbstract;
14+
use Symfony\Component\Console\Input\InputArgument;
15+
16+
/**
17+
* Stat.
18+
*
19+
* @author Mohamed Alsharaf <[email protected]>
20+
*/
21+
class Stat extends WorkspaceAbstract
22+
{
23+
/**
24+
* @var string
25+
*/
26+
protected $description = 'Display a live stream of container(s) resource usage statistics.';
27+
/**
28+
* @var string
29+
*/
30+
protected $childSignature = 'stat';
31+
/**
32+
* @var array
33+
*/
34+
protected $arguments = [
35+
'filter' => [
36+
'mode' => InputArgument::OPTIONAL,
37+
'description' => 'Filter the output by keyword',
38+
],
39+
];
40+
41+
/**
42+
* Main method to execute the command script.
43+
*
44+
* @return void
45+
*
46+
* @throws \Exception
47+
*/
48+
protected function fire()
49+
{
50+
$command = 'docker stats $(docker ps%s|grep -v "NAMES"|awk \'{ print $NF }\'|tr "\n" " ")';
51+
52+
$grepBy = $this->argument('filter');
53+
if (!empty($grepBy)) {
54+
$grepBy = '|grep "' . $grepBy . '" ';
55+
}
56+
57+
$this->getShellHelper()->execRealTime($command, $grepBy)->getOutput();
58+
}
59+
}

src/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
$application->add(new Command\Workspace\SilverStripeSake());
5353
$application->add(new Command\Workspace\Composer());
5454
$application->add(new Command\Workspace\Cp());
55+
$application->add(new Command\Workspace\Stat());
5556

5657
// Start console app
5758
$application->run();

0 commit comments

Comments
 (0)