Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Name | Details
ws:sites |Display list of available sites and their statuses.
ws:ssh |SSH into a container for a site within the workspace.
ws:start |Create and start containers for a site within the workspace. A wrapper to docker-compose up.
ws:stat |Display a live stream of container(s) resource usage statistics.
ws:stop |Stop services for a site within the workspace. A wrapper to docker stop command.
ws:update |Re-create local development site by updating the containers files, except for the directories site, env, solr/myindex.

Expand Down
59 changes: 59 additions & 0 deletions src/MooCommand/Command/Workspace/Stat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/*
* This file is part of the MooCommand package.
*
* (c) Mohamed Alsharaf <mohamed.alsharaf@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace MooCommand\Command\Workspace;

use MooCommand\Command\Workspace as WorkspaceAbstract;
use Symfony\Component\Console\Input\InputArgument;

/**
* Stat.
*
* @author Mohamed Alsharaf <mohamed.alsharaf@gmail.com>
*/
class Stat extends WorkspaceAbstract
{
/**
* @var string
*/
protected $description = 'Display a live stream of container(s) resource usage statistics.';
/**
* @var string
*/
protected $childSignature = 'stat';
/**
* @var array
*/
protected $arguments = [
'filter' => [
'mode' => InputArgument::OPTIONAL,
'description' => 'Filter the output by keyword',
],
];

/**
* Main method to execute the command script.
*
* @return void
*
* @throws \Exception
*/
protected function fire()
{
$command = 'docker stats $(docker ps%s|grep -v "NAMES"|awk \'{ print $NF }\'|tr "\n" " ")';

$grepBy = $this->argument('filter');
if (!empty($grepBy)) {
$grepBy = '|grep "' . $grepBy . '" ';
}

$this->getShellHelper()->execRealTime($command, $grepBy)->getOutput();
}
}
1 change: 1 addition & 0 deletions src/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
$application->add(new Command\Workspace\SilverStripeSake());
$application->add(new Command\Workspace\Composer());
$application->add(new Command\Workspace\Cp());
$application->add(new Command\Workspace\Stat());

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