gpt4 book ai didi

java - 如何使用 vSphere 和 Java 查找 esx 主机的 iops?

转载 作者:太空宇宙 更新时间:2023-11-04 14:58:13 27 4
gpt4 key购买 nike

我想了解 esx 主机的 iops。我可以使用以下代码连接到 esx 主机。

ServiceInstance si = new ServiceInstance(new URL(url), user, pass,
true);
ManagedEntity[] managedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("VirtualMachine");
ManagedEntity[] hostmanagedEntities = new InventoryNavigator(
si.getRootFolder()).searchManagedEntities("HostSystem");

通过使用上面的代码,我能够连接到主机并列出其上运行的所有虚拟机。

如何找到已连接主机的 iops?

最佳答案

我为找出计数器及其矩阵所做的工作如下:假设我使用您上面给出的代码(在此代码的开头)连接到 esx 主机。

     //set params to find out counter
groupinfo = "datastore";
nameinfo="datastoreIops";
rollup = "average";
//set interval
Calendar startTime = (Calendar) curTime.clone();
startTime.add(Calendar.MINUTE, -5);
PerformanceManager perfMgr = si.getPerformanceManager();
PerfProviderSummary summary = perfMgr.queryPerfProviderSummary(myhost);
int perfInterval = summary.getRefreshRate();
//get performance counters
PerfCounterInfo[] perfCounters = perfMgr.getPerfCounter();
int counter_id = 0;
//find id of right counter by iterating
for (int i = 0; i < perfCounters.length; i++) {
PerfCounterInfo perfCounterInfo = perfCounters[i];
String perfCounterString = perfCounterInfo.getNameInfo().getLabel() + " (" + perfCounterInfo.getGroupInfo().getKey() + ") in "
+ perfCounterInfo.getUnitInfo().getLabel() + " (" + perfCounterInfo.getStatsType().toString() + ")";
if (perfCounterInfo.getGroupInfo().getKey().equalsIgnoreCase(groupinfo)
&& perfCounterInfo.getNameInfo().getKey().equalsIgnoreCase(nameinfo)
&& perfCounterInfo.getRollupType().name().equalsIgnoreCase(rollup) )
{
counter_id = perfCounterInfo.getKey();
break;
}
}
int i3;
PerfMetricId[] queryAvailablePerfMetric = perfMgr.queryAvailablePerfMetric(myhost, null, null, perfInterval);
ArrayList<PerfMetricId> list = new ArrayList<PerfMetricId>();
for (int i2 = 0; i2 < queryAvailablePerfMetric.length; i2++) {
PerfMetricId perfMetricId = queryAvailablePerfMetric[i2];
if (counter_id == perfMetricId.getCounterId()) {
list.add(perfMetricId);
}
}
PerfMetricId[] pmis = list.toArray(new PerfMetricId[list.size()]);
PerfQuerySpec qSpec = new PerfQuerySpec();
qSpec.setEntity(myhost.getMOR());
qSpec.setMetricId(pmis);
qSpec.setStartTime(startTime);
qSpec.setEndTime(curTime);
qSpec.intervalId = perfInterval;

PerfEntityMetricBase[] pembs = perfMgr.queryPerf(new PerfQuerySpec[] { qSpec });

PerfEntityMetricBase val = pembs[0];
PerfEntityMetric pem = (PerfEntityMetric) val;
PerfMetricSeries[] vals = pem.getValue();

JSONObject perfout = new JSONObject();

for (int instanceid =0; vals != null && instanceid <vals.length;instanceid++ ) {

PerfMetricIntSeries val1 = (PerfMetricIntSeries) vals[instanceid];
String InstanceName = val1.getId().instance;
if (InstanceName.equals("")){
InstanceName="Total_"+instanceid;
}

long[] longs = val1.getValue();
long last_longs_value = longs[longs.length-1];
try {
perfout.put(InstanceName.replace(".", "-"), last_longs_value);
} catch (JSONException e) {
e.printStackTrace();
}
}
System.out.println(perfout);

可能对你有帮助..

关于java - 如何使用 vSphere 和 Java 查找 esx 主机的 iops?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22933572/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com