ArrayList<PerfMetricId> mMetrics = new ArrayList<PerfMetricId>(); if (listpermeid != null) { for (int index = 0; index < listpermeid.size(); ++index) { if (counters.containsKey(new Integer(listpermeid.get(index).getCounterId()))) { mMetrics.add(listpermeid.get(index)); } } }
PerfQuerySpec qSpec = new PerfQuerySpec(); qSpec.setEntity(vmmor); qSpec.getMetricId().addAll(mMetrics); qSpec.setEndTime(endTime); qSpec.setStartTime(beginTime);
List<PerfQuerySpec> qSpecs = new ArrayList<PerfQuerySpec>(); qSpecs.add(qSpec);
if (props != null) { Boolean flag = false; if (property.compareToIgnoreCase("name") < 0) { for (ObjectContent oc : props.getObjects()) { if (flag == true) { break; } String path = null; List<DynamicProperty> dps = oc.getPropSet();
if (dps != null) { for (DynamicProperty dp : dps) { path = dp.getName(); if (path.equalsIgnoreCase(property)) { String val = String.valueOf(dp.getVal()); ans = val; } if (path.equalsIgnoreCase("name")) { String value = (String) dp.getVal(); if (value.equals(clusterName)) { flag = true; break; } } } } } } else { for (ObjectContent oc : props.getObjects()) { if (flag == true) { break; } String path = null; List<DynamicProperty> dps = oc.getPropSet();
if (dps != null) { for (DynamicProperty dp : dps) { path = dp.getName(); if (path.equalsIgnoreCase("name")) { String value = (String) dp.getVal(); if (value.equals(clusterName)) { flag = true; } } if (path.equalsIgnoreCase(property)) { String val = String.valueOf(dp.getVal()); if (flag == true) { ans = val; break; } } } } } } }
return ans; }
publicstaticdoublegetClusterCpuUsageByClusterName(String clusterName)throws RuntimeFaultFaultMsg, DatatypeConfigurationException { double ans = 0.0; List<List<Long>> list = getClusterData(clusterName, "usage", "cpu"); long maxInner = 0; int times = 0; for (List<Long> listOuter : list) { long tempInner = 0; for (long inner : listOuter) { tempInner += inner; } if (tempInner > maxInner) { maxInner = tempInner; times = listOuter.size(); } } if (times != 0) { ans = (double) maxInner / times; } ans = ans / 100; return ans; }
publicstaticlonggetClusterEffectiveMemoryByClusterName(String clusterName)throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg { long ans = 0; String ret = getClusterPropertyByClusterName("summary.effectiveMemory", clusterName); ans = Long.valueOf(ret); return ans; }
同样以罗列集群名称的代码结束:
publicstatic List<String> getClusterNames() { List<String> list = new ArrayList<String>(); ManagedObjectReference rootFolder = serviceContent.getRootFolder(); try { TraversalSpec tSpec = getComputeResourceTraversalSpec(); PropertySpec propertySpec = new PropertySpec(); propertySpec.setAll(Boolean.FALSE); propertySpec.getPathSet().add("name"); propertySpec.setType("ClusterComputeResource");
ObjectSpec objectSpec = new ObjectSpec(); objectSpec.setObj(rootFolder); objectSpec.setSkip(Boolean.TRUE); objectSpec.getSelectSet().add(tSpec);
PropertyFilterSpec propertyFilterSpec = new PropertyFilterSpec(); propertyFilterSpec.getPropSet().add(propertySpec); propertyFilterSpec.getObjectSet().add(objectSpec);
List<PropertyFilterSpec> listfps = new ArrayList<PropertyFilterSpec>(1); listfps.add(propertyFilterSpec); List<ObjectContent> listobcont = retrievePropertiesAllObjects(listfps);