VMWare 提供了对主机,存储,网络等的监控功能,对于存储(Datastore)的性能,VMWare 从ReadIOPS,WriteIOPS,Write Latency, Read Latency 等等诸多角度去衡量存储性能,为创建主机,虚拟机等资源提供参考,同时提供灵活的查询方式,比如实时监控,日监控,周监控,月监控,年度监控等等。VMWare 提供了相应的接口供java或者.net进行调用,所以我们可以通过代码获取数据存储的性能数据。
下面的代码提供了一个提取监控数据的思路:
private void GetPerformance()
{
DateTime edt = DateTime.Now;
DateTime sdt = DateTime.Now.AddHours(-24);
ManagedObjectReference pmMor = util.getConnection().ServiceContent.perfManager;
ManagedObjectReference vmMor = util.getServiceUtil().getEntityByName("Datastore", "datastore1");
//---Get all performance monitor items---
List<PerfCounterInfo> perfCounterList = new List<PerfCounterInfo>();
PerfCounterInfo[] perfCounterInfos = (PerfCounterInfo[])util.getServiceUtil()
.GetDynamicProperty(pmMor, "perfCounter");
perfCounterInfos.ToList().ForEach(x =>
{
if (x.groupInfo.key.Equals("datastore")
&& x.nameInfo.key.Equals("datastoreReadIops")
&& x.rollupType == PerfSummaryType.average)
{
perfCounterList.Add(x);
return;
}
});
//---get all monitor condition---
List<PerfMetricId> perfMetricIdList = new List<PerfMetricId>();
PerfMetricId[] perfMetricIds = util.getConnection().Service
.QueryAvailablePerfMetric(pmMor, vmMor, sdt, true, edt, true, 300, true);
perfMetricIds.ToList().ForEach(x =>
{
if (perfCounterList.Where(item => item.key.Equals(x.counterId)).Count() > 0)
{
perfMetricIdList.Add(x);
}
});
PerfQuerySpec spec = new PerfQuerySpec()
{
metricId = perfMetricIdList.ToArray(),
entity = vmMor,
startTime = sdt,
endTime = edt,
startTimeSpecified = true,
endTimeSpecified = true,
//---time interval 20 seconds---
intervalId = 20,
intervalIdSpecified = true,
};
PerfEntityMetricBase[] metrics = util.getConnection().Service
.QueryPerf(pmMor, new PerfQuerySpec[] { spec });
}更多详细信息,请参考vSphere SDK。
本文介绍如何利用VMware的API通过Java或.NET代码获取数据存储的性能数据,包括实时监控、日监控、周监控、月监控和年度监控。
2220

被折叠的 条评论
为什么被折叠?



