use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class OpenManageJobService method syncMetricsDataJob.
private void syncMetricsDataJob(FacilitySoftwareConfig integration) {
wormholeApiClient.setServiceKey(serviceKeyConfig.getServiceKey());
// check the status of integration
try (OpenManageAPIClient client = createClient(integration)) {
checkConnection(client, integration);
List<RealTimeData> metricData = getMetricDatas(integration, client);
if (metricData.isEmpty()) {
logger.info("Not found any metrics data from " + integration.getName());
return;
}
wormholeApiClient.saveRealTimeData(metricData);
}
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class OpenManageJobTest method getMetricDatas.
@Test
public void getMetricDatas() {
Mockito.when(this.openManageAPIClient.getCommonResult(Plugin.class)).thenReturn(getCommonResult());
Mockito.when(this.openManageAPIClient.getDevicePowerMetrics("10074")).thenReturn(getPowerMetricsData());
Mockito.when(this.openManageAPIClient.getDeviceTemperatureMetrics("10074")).thenReturn(getDeviceTemperature());
Mockito.when(this.openManageAPIClient.getMetricsFromPowerManage(any(PowerManageMetricsRequestBody.class))).thenReturn(getDeviceMetricsResult());
Mockito.when(this.openManageAPIClient.getCommonResult(PowerSetting.class)).thenReturn(getPowerSettings());
FacilitySoftwareConfig config = new FacilitySoftwareConfig();
config.setId(createAsset().getAssetSource());
List<RealTimeData> metricDatas = openmanageJobService.getMetricDatas(config, openManageAPIClient);
for (RealTimeData data : metricDatas) {
if ("assetid1611766210404".equals(data.getId())) {
// power metrics
List<ValueUnit> values = data.getValues();
for (ValueUnit value : values) {
switch(value.getKey()) {
case MetricName.SERVER_AVERAGE_USED_POWER:
TestCase.assertEquals(0.074, value.getValueNum());
break;
// use powerManager value to override it
case MetricName.SERVER_POWER:
TestCase.assertEquals(0.072, value.getValueNum());
break;
case MetricName.SERVER_MINIMUM_USED_POWER:
TestCase.assertEquals(0.07, value.getValueNum());
break;
case MetricName.SERVER_PEAK_USED_POWER:
TestCase.assertEquals(0.08, value.getValueNum());
break;
case MetricName.SERVER_ENERGY_CONSUMPTION:
TestCase.assertEquals(800.0, value.getValueNum());
break;
case MetricName.SERVER_AVERAGE_TEMPERATURE:
TestCase.assertEquals(22.0, value.getValueNum());
break;
case MetricName.SERVER_TEMPERATURE:
TestCase.assertEquals(24.0, value.getValueNum());
break;
case MetricName.SERVER_PEAK_TEMPERATURE:
TestCase.assertEquals(30.0, value.getValueNum());
break;
case MetricName.SERVER_FRONT_TEMPERATURE:
TestCase.assertEquals(24.0, value.getValueNum());
break;
default:
TestCase.fail();
break;
}
}
} else {
TestCase.fail();
}
}
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class OpenManageJobTest method getMetricDatasTestNA.
@Test
public void getMetricDatasTestNA() {
Mockito.when(this.openManageAPIClient.getCommonResult(Plugin.class)).thenReturn(getCommonResult());
DevicePower powerMetrics = getPowerMetricsData();
powerMetrics.setMinimumPower("N/A");
Mockito.when(this.openManageAPIClient.getDevicePowerMetrics("10074")).thenReturn(powerMetrics);
Mockito.when(this.openManageAPIClient.getDeviceTemperatureMetrics("10074")).thenReturn(getDeviceTemperature());
Mockito.when(this.openManageAPIClient.getMetricsFromPowerManage(any(PowerManageMetricsRequestBody.class))).thenReturn(getDeviceMetricsResult());
Mockito.when(this.openManageAPIClient.getCommonResult(PowerSetting.class)).thenReturn(getPowerSettings());
FacilitySoftwareConfig config = new FacilitySoftwareConfig();
config.setId(createAsset().getAssetSource());
List<RealTimeData> metricDatas = openmanageJobService.getMetricDatas(config, openManageAPIClient);
for (RealTimeData data : metricDatas) {
if ("assetid1611766210404".equals(data.getId())) {
// power metrics
List<ValueUnit> values = data.getValues();
for (ValueUnit value : values) {
switch(value.getKey()) {
case MetricName.SERVER_AVERAGE_USED_POWER:
TestCase.assertEquals(0.074, value.getValueNum());
break;
// use powerManager value to override it
case MetricName.SERVER_POWER:
TestCase.assertEquals(0.072, value.getValueNum());
break;
case MetricName.SERVER_MINIMUM_USED_POWER:
TestCase.fail("Should not contain the " + MetricName.SERVER_MINIMUM_USED_POWER);
break;
case MetricName.SERVER_PEAK_USED_POWER:
TestCase.assertEquals(0.08, value.getValueNum());
break;
case MetricName.SERVER_ENERGY_CONSUMPTION:
TestCase.assertEquals(800.0, value.getValueNum());
break;
case MetricName.SERVER_AVERAGE_TEMPERATURE:
TestCase.assertEquals(22.0, value.getValueNum());
break;
case MetricName.SERVER_TEMPERATURE:
TestCase.assertEquals(24.0, value.getValueNum());
break;
case MetricName.SERVER_PEAK_TEMPERATURE:
TestCase.assertEquals(30.0, value.getValueNum());
break;
case MetricName.SERVER_FRONT_TEMPERATURE:
TestCase.assertEquals(24.0, value.getValueNum());
break;
default:
TestCase.fail();
break;
}
}
} else {
TestCase.fail();
}
}
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetController method removeRealTimeData.
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/realtimedata/{expiredtimerange}", method = RequestMethod.DELETE)
public void removeRealTimeData(@PathVariable("expiredtimerange") Long expiredtimerange) {
long currentTime = System.currentTimeMillis();
if (expiredtimerange < FlowgateConstant.DEFAULTEXPIREDTIMERANGE) {
expiredtimerange = FlowgateConstant.DEFAULTEXPIREDTIMERANGE;
}
List<RealTimeData> dataToBeDeleted = realtimeDataRepository.getRealTimeDatabtTimeRange(currentTime - expiredtimerange);
while (!dataToBeDeleted.isEmpty()) {
for (RealTimeData realtimedata : dataToBeDeleted) {
realtimeDataRepository.deleteById(realtimedata.getId());
}
dataToBeDeleted = realtimeDataRepository.getRealTimeDatabtTimeRange(currentTime - expiredtimerange);
}
}
use of com.vmware.flowgate.common.model.RealTimeData 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