Skip to content

Commit

Permalink
Feature: new command to display containers resource stats
Browse files Browse the repository at this point in the history
  • Loading branch information
satrun77 committed Feb 9, 2017
1 parent a4491da commit f2b8d6c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
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 <[email protected]>
*
* 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 <[email protected]>
*/
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();

0 comments on commit f2b8d6c

Please sign in to comment.