如何获取主机&x27;通过PHP在网站上显示Vmware ESXi 5.5中的内存使用情况?
我在任何地方搜索如何从Vmware ESXi 5.5获取主机的内存使用情况,以通过PHP在网站上显示,但我找不到答案 我在github上找到了以下代码:如何获取主机&x27;通过PHP在网站上显示Vmware ESXi 5.5中的内存使用情况?,php,soap,vmware,vsphere,esxi,Php,Soap,Vmware,Vsphere,Esxi,我在任何地方搜索如何从Vmware ESXi 5.5获取主机的内存使用情况,以通过PHP在网站上显示,但我找不到答案 我在github上找到了以下代码: <?php class soapclientd extends soapclient { public $action = false; public function __construct($wsdl, $options = array()) { parent::__construct($ws
<?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);
从代码中,您只遍历VM属性的方法对象
host.summary.quickStats.overallMemoryUsage
对于主机级别,需要遍历到主机文件夹。比如:
主机系统
并从以下位置访问主机内存统计信息:
从代码中,您只遍历VM属性的方法对象
host.summary.quickStats.overallMemoryUsage
对于主机级别,需要遍历到主机文件夹。比如:
主机系统
并从以下位置访问主机内存统计信息:
“这不是我所需要的”是什么意思?错误?错误的数据?你试过询问脚本的作者吗?它只显示虚拟机的列表,但我需要主机的内存使用情况。有人已经问了同样的问题,但作者没有回答。什么是“…这不是我所需要的工作”的意思?错误?错误的数据?你试过询问脚本的作者吗?它只显示虚拟机的列表,但我需要主机的内存使用情况。有人已经问了同样的问题,但作者没有回答。
host.summary.quickStats.overallMemoryUsage