Beispiel #1
0
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $versionList = array();
     // ############################
     // System (LSB Version)
     // ############################
     $versionRow = array('system' => 'System', 'version' => UnixUtility::lsbSystemDescription());
     $versionList[] = array_values($versionRow);
     // ############################
     // PHP
     // ############################
     $versionList[] = array('PHP', phpversion());
     // ############################
     // MySQL
     // ############################
     $query = 'SHOW VARIABLES LIKE \'version\'';
     $versionRow = DatabaseConnection::getList($query);
     $versionList[] = array('MySQL', $versionRow['version']);
     // ############################
     // Apache
     // ############################
     $versionRow = array('system' => 'Apache', 'version' => 'Unknown');
     $command = new CommandBuilder('apache2ctl', '-v');
     $command->setOutputRedirect(CommandBuilder::OUTPUT_REDIRECT_NO_STDERR);
     $execOutput = $command->execute()->getOutput();
     foreach ($execOutput as $execOutputLine) {
         if (strpos($execOutputLine, ':') !== false) {
             list($tmpKey, $tmpVersion) = explode(':', trim($execOutputLine), 2);
             switch (strtolower($tmpKey)) {
                 case 'server version':
                     $versionRow['version'] = trim($tmpVersion);
                     break;
             }
         }
     }
     $versionList[] = array_values($versionRow);
     // ############################
     // Docker
     // ############################
     $versionRow = array('system' => 'Docker', 'version' => \CliTools\Utility\UnixUtility::dockerVersion());
     $versionList[] = array_values($versionRow);
     // ############################
     // CliTools
     // ############################
     $versionList[] = array('CliTools', CLITOOLS_COMMAND_VERSION);
     // ########################
     // Output
     // ########################
     /** @var \Symfony\Component\Console\Helper\Table $table */
     $table = new Table($output);
     $table->setHeaders(array('System', 'Version'));
     foreach ($versionList as $versionRow) {
         $table->addRow(array_values($versionRow));
     }
     $table->render();
     return 0;
 }
Beispiel #2
0
 /**
  * Generate system info
  *
  * @return string
  */
 protected function generateSystemInfo()
 {
     $ret = array();
     $leftCol = array();
     $rightCol = array();
     // ##################
     // Left: System info
     // ##################
     $labelLength = 12;
     $bytesPadding = 10;
     $cpuCount = UnixUtility::cpuCount();
     $memSize = FormatUtility::bytes(UnixUtility::memorySize());
     $kernelVersion = UnixUtility::kernelVersion();
     $dockerVersion = UnixUtility::dockerVersion();
     $mountInfoList = UnixUtility::mountInfoList();
     // Padding
     $memSize = str_pad($memSize, $bytesPadding, ' ', STR_PAD_LEFT);
     // Basic sys informations
     $leftCol[] = str_pad('Linux', $labelLength, ' ', STR_PAD_LEFT) . ': ' . $kernelVersion;
     if (!empty($dockerVersion)) {
         $leftCol[] = str_pad('Docker', $labelLength, ' ', STR_PAD_LEFT) . ': ' . $dockerVersion;
     }
     $leftCol[] = str_pad('CPU', $labelLength, ' ', STR_PAD_LEFT) . ': ' . $cpuCount . ' Cores';
     $leftCol[] = str_pad('Memory', $labelLength, ' ', STR_PAD_LEFT) . ': ' . $memSize;
     // Mount info list
     foreach ($mountInfoList as $mount => $stats) {
         $capacity = FormatUtility::bytes($stats['capacity']);
         $usage = $stats['usage'];
         if ($mount === '/') {
             $mount = 'root';
         }
         // padding
         $mount = str_pad($mount, $labelLength, ' ', STR_PAD_LEFT);
         $capacity = str_pad($capacity, $bytesPadding, ' ', STR_PAD_LEFT);
         $leftCol[] = $mount . ': ' . $capacity . ' (' . $usage . ' in use)';
     }
     // ##################
     // Right: Network interfaces
     // ##################
     $labelLength = 6;
     // Network list (but not docker interfaces)
     $netInterfaceList = UnixUtility::networkInterfaceList('/^((?!docker).)*$/i');
     foreach ($netInterfaceList as $netName => $netConf) {
         $netName = str_pad($netName, $labelLength, ' ', STR_PAD_LEFT);
         $rightCol[] = $netName . ': ' . $netConf['ipaddress'];
     }
     // ##################
     // Build output
     // ##################
     // Get max number of rows
     $maxLines = max(count($leftCol), count($rightCol));
     $colLeftWidth = 54;
     $colRightWidth = 30;
     for ($i = 0; $i < $maxLines; $i++) {
         $leftColLine = '';
         $rightColLine = '';
         // Get col-cell if available
         if (isset($leftCol[$i])) {
             $leftColLine = $leftCol[$i];
         }
         // Get col-cell if available
         if (isset($rightCol[$i])) {
             $rightColLine = $rightCol[$i];
         }
         // Fill with required length
         $leftColLine = str_pad($leftColLine, $colLeftWidth, ' ', STR_PAD_RIGHT);
         $rightColLine = str_pad($rightColLine, $colRightWidth, ' ', STR_PAD_RIGHT);
         // Fix max length
         $leftColLine = substr($leftColLine, 0, $colLeftWidth);
         $rightColLine = substr($rightColLine, 0, $colRightWidth);
         // Build table row
         $ret[] = $leftColLine . $rightColLine;
     }
     return implode("\n", $ret);
 }