예제 #1
0
 public function getCpuIdle(CpuMemDto $cpuMemDto)
 {
     $commandsDto = new CommandsExecutionDto();
     $commandsDto->setCommandName(CommandsConstants::GET_CPU_IDLE);
     /**
      * @var CpuMemDto $cpuInfo
      **/
     $cpuInfo = $this->getCommandExecutionResult($commandsDto);
     $cpuMemDto->setCpuIdle($cpuInfo->getCpuIdle());
     return $cpuMemDto;
 }
예제 #2
0
 protected static function getCpuIdle()
 {
     $cpuMemDto = new CpuMemDto();
     $cmdResult = `top -bn2 | grep 'id,' | awk '{ printf("%-8s", \$8); }'`;
     $splitResult = preg_split('/\\s+/', $cmdResult);
     $idleArr = [];
     foreach ($splitResult as $item) {
         $item = str_replace(",", ".", trim($item));
         if (is_numeric($item)) {
             $idleArr[] = (double) $item;
         }
     }
     $res = array_pop($idleArr);
     $cpuMemDto->setCpuIdle($res);
     return $cpuMemDto;
 }