VI SDK集群内存

时间:2014-08-01 05:30:55

标签: java sdk virtual-machine

我需要帮助使用Vi Java SDK程序获取集群保留内存和已用内存

我可以使用以下代码获取群集的总内存。

ClusterComputeResource crs=(ClusterComputeResource) mes[i];
ClusterConfigInfo clusconfig=crs.getConfiguration();
ComputeResourceSummary cm=crs.getSummary();
double mem=cm.getTotalMemory()/1099511627776D;
double round=Math.round(mem);
String str = String.format("%1.2f", mem);
double totalmemory = Double.valueOf(str);
System.out.println("Cluster NAME " + crs.getName());
System.out.println("Cluster Memory " + totalmemory +"TB");

任何人都可以进一步指导我获取群集的保留和已用内存。

请提前帮助和致谢。

1 个答案:

答案 0 :(得分:0)

阅读文档,数据对象ClusterComputeResource还有一个名为

的属性

effectiveMemory : Effective memory resources (in MB) available to run virtual machines. This is the aggregated effective resource level from all running hosts. Hosts that are in maintenance mode or are unresponsive are not counted. Resources used by the VMware Service Console are not included in the aggregate. This value represents the amount of resources available for the root resource pool for running virtual machines.

现在要计算已用内存,你必须做一些计算。这不是那么直接(TotalMemory - EffectiveMem)。

编辑:我想你想要存储容量? 要检索群集的容量,请检查Cluster对象是否具有数据存储对象的数组。遍历数组并检索数据存储容量。

ManagedEntity[] clusters = new InventoryNavigator(rootFolder).searchManagedEntities("ClusterComputeResource");      
ClusterComputeResource cluster = (ClusterComputeResource)clusters[0];
Datastore[] datastores = cluster.getDatastores();
for(Datastore datastore: datastores)
    System.out.println("Capacity for datastore " +datastore.getName() + ": " + datastore.getSummary().capacity +" bytes");