2016-09-27 175 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 
相关问题