use of com.vmware.vim.binding.vim.PerformanceManager.QuerySpec in project flowgate by vmware.
the class VCDataService method feedHostUsageData.
public void feedHostUsageData(VsphereClient vsphereClient, String assetId, ManagedObjectReference hostRef) {
List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
RealTimeData realTimeData = new RealTimeData();
realTimeData.setAssetID(assetId);
List<ValueUnit> valueUnits = new ArrayList<ValueUnit>();
PerformanceManager performanceManager = vsphereClient.getPerformanceManager();
Map<Integer, String> counters = getMetricsCounters(performanceManager);
if (counters == null || counters.isEmpty()) {
logger.error("Asset: {} failed to get performance counters", assetId);
return;
}
List<MetricId> metricIdList = getPerformenceMetricsIds(performanceManager, hostRef, counters);
if (metricIdList == null || metricIdList.isEmpty()) {
logger.error("Asset: {} failed to get performance metricIds", assetId);
return;
}
// fill spec info
ProviderSummary summary = performanceManager.queryProviderSummary(hostRef);
int perfInterval = summary.getRefreshRate();
QuerySpec[] specs = new QuerySpecImpl[1];
specs[0] = new QuerySpecImpl();
specs[0].setEntity(hostRef);
specs[0].setMetricId(metricIdList.toArray(new MetricId[metricIdList.size()]));
specs[0].setIntervalId(perfInterval);
specs[0].setMaxSample(15);
// get metrics value
EntityMetricBase[] metricBase = performanceManager.queryStats(specs);
if (metricBase == null || metricBase.length <= 0) {
logger.error("Asset: {} failed to get performance metricBase", assetId);
return;
}
List<ValueUnit> powerValueUnits = new ArrayList<>(15);
for (EntityMetricBase entityMetricBase : metricBase) {
/*
(vim.EntityMetric) {
dynamicType = null,
dynamicProperty = null,
entity = ManagedObjectReference: type = HostSystem, value = host-65, serverGuid = null,
sampleInfo = (vim.SampleInfo) [
(vim.SampleInfo) {
dynamicType = null,
dynamicProperty = null,
timestamp = java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+00:00",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2020,MONTH=11,WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=10,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=2,MINUTE=12,SECOND=20,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0],
interval = 20
}...
],
value = (vim.MetricSeries) [
(vim.IntSeries) {
dynamicType = null,
dynamicProperty = null,
id = (vim.MetricId) {
dynamicType = null,
dynamicProperty = null,
counterId = 125,
instance =
},
value = (LONG) [
667,
251,
96,
298,
99,
119,
492,
318,
98,
218,
128,
141,
1224,
358,
133
]
}...
*/
EntityMetric entityMetric = (EntityMetric) entityMetricBase;
/*
(vim.IntSeries) {
dynamicType = null,
dynamicProperty = null,
id = (vim.MetricId) {
dynamicType = null,
dynamicProperty = null,
counterId = 125,
instance =
},
value = (LONG) [101,134,667,282,90,224,99,129,667,251,96,298,99,119,492]
}
*/
MetricSeries[] metricSeries = entityMetric.getValue();
/*
(vim.SampleInfo) {
dynamicType = null,
dynamicProperty = null,
timestamp = java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT+00:00",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2020,MONTH=11,WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=10,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=2,MINUTE=7,SECOND=40,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0],
interval = 20
}
*/
SampleInfo[] sampleInfos = entityMetric.getSampleInfo();
for (MetricSeries metricSerie : metricSeries) {
if (metricSerie instanceof IntSeries) {
IntSeries intSeries = (IntSeries) metricSerie;
long[] values = intSeries.getValue();
int counterId = metricSerie.getId().getCounterId();
for (int index = 0; index < values.length; index++) {
long timeStamp = sampleInfos[index].getTimestamp().getTimeInMillis();
ValueUnit valueUnit = new ValueUnit();
long value = values[index];
switch(counters.get(counterId)) {
case VCConstants.HOST_CPU_GROUP + VCConstants.HOST_METRIC_USAGE:
valueUnit.setKey(MetricName.SERVER_CPUUSAGE);
valueUnit.setValueNum(value / 100.0);
valueUnit.setUnit(ValueUnit.MetricUnit.percent.name());
break;
case VCConstants.HOST_CPU_GROUP + VCConstants.HOST_METRIC_USAGEMHZ:
valueUnit.setKey(MetricName.SERVER_CPUUSEDINMHZ);
valueUnit.setValueNum(value);
valueUnit.setUnit(ValueUnit.MetricUnit.Mhz.name());
break;
case VCConstants.HOST_MEMORY_GROUP + VCConstants.HOST_METRIC_USAGE:
valueUnit.setKey(MetricName.SERVER_MEMORYUSAGE);
valueUnit.setValueNum(value / 100.0);
valueUnit.setUnit(ValueUnit.MetricUnit.percent.name());
break;
case VCConstants.HOST_MEMORY_GROUP + VCConstants.HOST_METRIC_MEM_ACTIVE:
valueUnit.setKey(MetricName.SERVER_ACTIVEMEMORY);
valueUnit.setValueNum(value);
valueUnit.setUnit(ValueUnit.MetricUnit.kB.name());
break;
case VCConstants.HOST_MEMORY_GROUP + VCConstants.HOST_METRIC_MEM_SHARED:
valueUnit.setKey(MetricName.SERVER_SHAREDMEMORY);
valueUnit.setValueNum(value);
valueUnit.setUnit(ValueUnit.MetricUnit.kB.name());
break;
case VCConstants.HOST_MEMORY_GROUP + VCConstants.HOST_METRIC_MEM_CONSUMED:
valueUnit.setKey(MetricName.SERVER_CONSUMEDMEMORY);
valueUnit.setValueNum(value);
valueUnit.setUnit(ValueUnit.MetricUnit.kB.name());
break;
case VCConstants.HOST_MEMORY_GROUP + VCConstants.HOST_METRIC_MEM_SWAP:
valueUnit.setKey(MetricName.SERVER_SWAPMEMORY);
valueUnit.setValueNum(value);
valueUnit.setUnit(ValueUnit.MetricUnit.kB.name());
break;
case VCConstants.HOST_MEMORY_GROUP + VCConstants.HOST_METRIC_MEM_BALLON:
valueUnit.setKey(MetricName.SERVER_BALLOONMEMORY);
valueUnit.setValueNum(value);
valueUnit.setUnit(ValueUnit.MetricUnit.kB.name());
break;
case VCConstants.HOST_DISK_GROUP + VCConstants.HOST_METRIC_USAGE:
valueUnit.setKey(MetricName.SERVER_STORAGEIORATEUSAGE);
valueUnit.setValueNum(value);
valueUnit.setUnit(ValueUnit.MetricUnit.kBps.name());
break;
case VCConstants.HOST_NETWORK_GROUP + VCConstants.HOST_METRIC_USAGE:
valueUnit.setKey(MetricName.SERVER_NETWORKUTILIZATION);
valueUnit.setValueNum(value);
valueUnit.setUnit(ValueUnit.MetricUnit.kBps.name());
break;
case VCConstants.HOST_POWER_GROUP + VCConstants.HOST_METRIC_POWER_POWER:
valueUnit.setKey(MetricName.SERVER_POWER);
valueUnit.setValueNum(valueUnit.translateUnit(value, ValueUnit.MetricUnit.W, ValueUnit.MetricUnit.kW));
valueUnit.setUnit(ValueUnit.MetricUnit.kW.name());
powerValueUnits.add(valueUnit);
break;
case VCConstants.HOST_POWER_GROUP + VCConstants.HOST_METRIC_POWER_ENERGY:
valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
// This extraidentifier is the start time
valueUnit.setExtraidentifier(String.valueOf(timeStamp - (perfInterval * 1000)));
valueUnit.setValueNum(value * JOULETOKWHRATE);
valueUnit.setUnit(ValueUnit.MetricUnit.kWh.name());
break;
}
valueUnit.setTime(timeStamp);
valueUnits.add(valueUnit);
}
}
}
}
if (valueUnits == null || valueUnits.isEmpty()) {
logger.error("ValueUnits of asset: {} is empty.", assetId);
return;
}
valueUnits.addAll(getMinMaxAvgValueUnit(powerValueUnits));
realTimeData.setValues(valueUnits);
realTimeData.setTime(valueUnits.get(0).getTime());
realTimeDatas.add(realTimeData);
restClient.saveRealTimeData(realTimeDatas);
}
Aggregations