Beispiel #1
0
 /**
  * Check system disk usage
  */
 protected function systemCheckDiskUsage()
 {
     $diskUsageLimit = abs($this->getApplication()->getConfigValue('syscheck', 'diskusage', 0));
     if (!empty($diskUsageLimit)) {
         $mountInfoList = UnixUtility::mountInfoList();
         foreach ($mountInfoList as $mount => $stats) {
             $usageInt = $stats['usageInt'];
             $statsLine = array($usageInt . '% used', \CliTools\Utility\FormatUtility::bytes($stats['free']) . ' free');
             if ($usageInt >= $diskUsageLimit) {
                 $this->sysCheckMessageList[] = 'Mount "' . $mount . '" exceeds limit of ' . $diskUsageLimit . '% (' . implode(', ', $statsLine) . ')';
             }
         }
     }
 }
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);
 }