2016-09-27 54 views
1

我搜索eveywhere如何獲得從Vmware ESXi 5.5獲得的主機的內存使用量,通過PHP在網站上顯示,但我找不到答案。如何從Vmware ESXi 5.5獲取主機的內存使用情況,並通過PHP在網站上顯示?

我發現github上下面的代碼:

<?php 
class soapclientd extends soapclient 
{ 
    public $action = false; 

    public function __construct($wsdl, $options = array()) 
    { 
     parent::__construct($wsdl, $options); 
    } 

    public function __doRequest($request, $location, $action, $version, $one_way = 0) 
    { 
//  echo '<pre>' . htmlspecialchars(str_replace(array ('<ns', '></'), array (PHP_EOL . '<ns', '>'.PHP_EOL.'</'), $request)) . '</pre>'; 
     $resp = parent::__doRequest($request, $location, $action, $version, $one_way); 
     return $resp; 
    } 

} 

$client = new soapclientd('vimService.wsdl', array ('location' => 'http://10.1.0.47/sdk', 'trace' => 1)); 

try 
{ 
    $request = new stdClass(); 
    $request->_this = array ('_' => 'ServiceInstance', 'type' => 'ServiceInstance'); 
    $response = $client->__soapCall('RetrieveServiceContent', array((array)$request)); 
} catch (Exception $e) 
{ 
    echo $e->getMessage(); 
    exit; 
} 
$ret = $response->returnval; 

try 
{ 
    $request = new stdClass(); 
    $request->_this = $ret->sessionManager; 
    $request->userName = 'root'; 
    $request->password = 'abc123456'; 
    $response = $client->__soapCall('Login', array((array)$request)); 
} catch (Exception $e) 
{ 
    echo $e->getMessage(); 
    exit; 
} 

$ss1 = new soapvar(array ('name' => 'FolderTraversalSpec'), SOAP_ENC_OBJECT, null, null, 'selectSet', null); 
$ss2 = new soapvar(array ('name' => 'DataCenterVMTraversalSpec'), SOAP_ENC_OBJECT, null, null, 'selectSet', null); 
$a = array ('name' => 'FolderTraversalSpec', 'type' => 'Folder', 'path' => 'childEntity', 'skip' => false, $ss1, $ss2); 

$ss = new soapvar(array ('name' => 'FolderTraversalSpec'), SOAP_ENC_OBJECT, null, null, 'selectSet', null); 
$b = array ('name' => 'DataCenterVMTraversalSpec', 'type' => 'Datacenter', 'path' => 'vmFolder', 'skip' => false, $ss); 

$res = null; 
try 
{ 
    $request = new stdClass(); 
    $request->_this = $ret->propertyCollector; 
    $request->specSet = array (
     'propSet' => array (
      array ('type' => 'VirtualMachine', 'all' => 0, 'pathSet' => array ('name', 'guest.ipAddress', 'guest.guestState', 'runtime.powerState', 'config.hardware.numCPU', 'config.hardware.memoryMB')), 
     ), 
     'objectSet' => array (
      'obj' => $ret->rootFolder, 
      'skip' => false, 
      'selectSet' => array (
       new soapvar($a, SOAP_ENC_OBJECT, 'TraversalSpec'), 
       new soapvar($b, SOAP_ENC_OBJECT, 'TraversalSpec'), 
       ), 
      ) 
     ); 
    $res = $client->__soapCall('RetrieveProperties', array((array)$request)); 
} catch (Exception $e) 
{ 
    echo $e->getMessage(); 
} 
echo '<pre>'; 
print_r($res); 

但是這是不工作我需要什麼。

我正在嘗試從HostHardwareSummary或​​HostSystem託管對象中撤回主機詳細信息。 你知道如何去做這件事。我似乎無法擺脫對象/數據對象系統的頭腦。 我只想要細節,如CPU使用率和RAM使用情況。

This is the memory usage i want to pull using php

如果你們能幫助我,我會真正體會到

謝謝

+0

是什麼_「......這是不工作我需要什麼」 _是什麼意思?錯誤?錯誤的數據?你有沒有試過詢問劇本的作者? –

+0

它只顯示虛擬機的列表,但我需要主機的內存使用情況。 有人已經問過同樣的問題,但沒有作者的回答。 –

回答

0

從代碼,你只遍歷到虛擬機性能的方法的對象。

$b = array ('name' => 'DataCenterVMTraversalSpec', 'type' => 'Datacenter', 'path' => 'vmFolder', 'skip' => false, $ss); 

對於主機級別,您需要遍歷主機文件夾。是這樣的: HostSystem

$bs = array ('name' => 'DataCenterVMTraversalSpec', 'type' => 'Datacenter', 'path' => 'hostFolder', 'skip' => false, $ss); 

和訪問主機內存統計來自:

host.summary.quickStats.overallMemoryUsage 
相關問題