use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetControllerTest method createServerHostRealTimeData.
RealTimeData createServerHostRealTimeData(long time) {
double[] storageIORateUsageValues = { 330, 98, 57, 852, 224, 95, 209, 66, 56, 798, 236, 81, 213, 63, 61 };
double[] memoryUsageValues = { 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22, 87.22 };
double[] cpuUsedInMhzValues = { 746, 570, 552, 844, 651, 566, 552, 569, 538, 836, 655, 565, 571, 551, 570 };
double[] cpuUsageValues = { 4.67, 3.57, 3.46, 5.28, 4.08, 3.55, 3.45, 3.56, 3.37, 5.23, 4.1, 3.53, 3.57, 3.45, 3.57 };
double[] activeMemoryValues = { 1561416, 1561416, 2065824, 2065824, 2065824, 2065428, 2065428, 2065428, 1729924, 1729924, 1729924, 1561072, 1561072, 1561072, 2063852 };
double[] sharedMemoryValues = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
double[] consumedMemoryValues = { 18291220, 18291236, 18291236, 18291236, 18291252, 18291252, 18291252, 18291156, 18291156, 18291200, 18291060, 18291172, 18291172, 18291188, 18291188 };
double[] swapMemoryValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
double[] balloonMemoryValues = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
double[] networkUtilizationValues = { 146, 18, 15, 16, 16, 12, 9, 16, 10, 16, 17, 12, 12, 19, 29 };
double[] powerValues = { 0.069, 0.069, 0.069, 0.069, 0.07, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069, 0.069 };
double[] energyValues = { 0.00038805555555555555, 0.0003833333333333333, 0.0003833333333333333, 0.0003869444444444444, 0.00038888888888888887, 0.00038805555555555555, 0.0003833333333333333, 0.0003833333333333333, 0.0003833333333333333, 0.00038555555555555554, 0.00038805555555555555, 0.0003833333333333333, 0.0003833333333333333, 0.0003833333333333333, 0.00038555555555555554 };
List<ValueUnit> valueUnits = new ArrayList<>();
ValueUnit valueUnit;
long startTime = 0;
long endTime = 0;
long maxValueTime = 0;
long minValueTime = 0;
for (int i = 0; i < 15; i++) {
long tempTime = time + ((i + 1) * 20000);
if (i == 0) {
startTime = tempTime;
minValueTime = tempTime;
}
if (i == 14) {
endTime = tempTime;
}
if (i == 4) {
maxValueTime = tempTime;
}
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_STORAGEIORATEUSAGE);
valueUnit.setUnit(MetricUnit.kBps.name());
valueUnit.setValueNum(storageIORateUsageValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_MEMORYUSAGE);
valueUnit.setUnit(MetricUnit.percent.name());
valueUnit.setValueNum(memoryUsageValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_CPUUSEDINMHZ);
valueUnit.setUnit(MetricUnit.Mhz.name());
valueUnit.setValueNum(cpuUsedInMhzValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_CPUUSAGE);
valueUnit.setUnit(MetricUnit.percent.name());
valueUnit.setValueNum(cpuUsageValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_ACTIVEMEMORY);
valueUnit.setUnit(MetricUnit.kB.name());
valueUnit.setValueNum(activeMemoryValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_SHAREDMEMORY);
valueUnit.setUnit(MetricUnit.kB.name());
valueUnit.setValueNum(sharedMemoryValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_CONSUMEDMEMORY);
valueUnit.setUnit(MetricUnit.kB.name());
valueUnit.setValueNum(consumedMemoryValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_SWAPMEMORY);
valueUnit.setUnit(MetricUnit.kB.name());
valueUnit.setValueNum(swapMemoryValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_BALLOONMEMORY);
valueUnit.setUnit(MetricUnit.kB.name());
valueUnit.setValueNum(balloonMemoryValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_NETWORKUTILIZATION);
valueUnit.setUnit(MetricUnit.kBps.name());
valueUnit.setValueNum(networkUtilizationValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_POWER);
valueUnit.setUnit(MetricUnit.kW.name());
valueUnit.setValueNum(powerValues[i]);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(tempTime);
valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
valueUnit.setExtraidentifier(String.valueOf(tempTime - 20000));
valueUnit.setUnit(MetricUnit.kWh.name());
valueUnit.setValueNum(energyValues[i]);
valueUnits.add(valueUnit);
}
valueUnit = new ValueUnit();
valueUnit.setTime(endTime);
valueUnit.setExtraidentifier(startTime + FlowgateConstant.SEPARATOR + minValueTime);
valueUnit.setKey(MetricName.SERVER_MINIMUM_USED_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.069);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(endTime);
valueUnit.setExtraidentifier(startTime + FlowgateConstant.SEPARATOR + maxValueTime);
valueUnit.setKey(MetricName.SERVER_PEAK_USED_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.07);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(endTime);
valueUnit.setExtraidentifier(String.valueOf(startTime));
valueUnit.setKey(MetricName.SERVER_AVERAGE_USED_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.06906666666666665);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(time);
valueUnit.setKey(MetricName.SERVER_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.56);
valueUnits.add(valueUnit);
String sinceTime = String.valueOf(time - 900000l);
valueUnit = new ValueUnit();
String minimumPowerTime = String.valueOf(time - 30000l);
valueUnit.setTime(time);
valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR + minimumPowerTime);
valueUnit.setKey(MetricName.SERVER_MINIMUM_USED_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.5);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
String peakPowerTime = String.valueOf(time - 60000l);
valueUnit.setTime(time);
valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR + peakPowerTime);
valueUnit.setKey(MetricName.SERVER_PEAK_USED_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.8);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(time);
valueUnit.setExtraidentifier(sinceTime);
valueUnit.setKey(MetricName.SERVER_AVERAGE_USED_POWER);
valueUnit.setUnit(MetricUnit.kW.toString());
valueUnit.setValueNum(0.6);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(time);
valueUnit.setExtraidentifier(sinceTime);
valueUnit.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
valueUnit.setUnit(MetricUnit.kWh.toString());
valueUnit.setValueNum(356);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(time);
valueUnit.setExtraidentifier(sinceTime);
valueUnit.setKey(MetricName.SERVER_AVERAGE_TEMPERATURE);
valueUnit.setUnit(MetricUnit.C.toString());
valueUnit.setValueNum(24);
valueUnits.add(valueUnit);
valueUnit = new ValueUnit();
valueUnit.setTime(time);
String peakTemperatureTime = String.valueOf(time - 60000l);
valueUnit.setExtraidentifier(sinceTime + FlowgateConstant.SEPARATOR + peakTemperatureTime);
valueUnit.setKey(MetricName.SERVER_PEAK_TEMPERATURE);
valueUnit.setUnit(MetricUnit.C.toString());
valueUnit.setValueNum(30);
valueUnits.add(valueUnit);
RealTimeData realTimeData = new RealTimeData();
realTimeData.setId(UUID.randomUUID().toString());
realTimeData.setAssetID("0001bdc8b25d4c2badfd045ab61aabfa");
realTimeData.setValues(valueUnits);
realTimeData.setTime(time);
return realTimeData;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetControllerTest method testGetMetricDataForOther.
@Test
public void testGetMetricDataForOther() {
Asset sensor = createSensor();
assetRepository.save(sensor);
String sensorId = sensor.getId();
long time = System.currentTimeMillis();
int duration = 30 * 60 * 1000;
long startTime = time - duration;
List<RealTimeData> realTimeDatas = new ArrayList<>();
RealTimeData tempRealTimeData = createTemperatureSensorRealtimeData(startTime, sensorId);
realTimeDatas.add(tempRealTimeData);
List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
ValueUnit tempValue = new ValueUnit();
tempValue.setValueNum(25);
tempValue.setTime(startTime + 5 * 60 * 1000);
tempValue.setUnit(MetricUnit.C.toString());
tempValue.setKey(MetricName.TEMPERATURE);
valueunits.add(tempValue);
RealTimeData realTimeData = new RealTimeData();
realTimeData.setId(UUID.randomUUID().toString());
realTimeData.setAssetID(sensorId);
realTimeData.setValues(valueunits);
realTimeData.setTime(startTime + 5 * 60 * 1000);
realTimeDatas.add(realTimeData);
realtimeDataRepository.saveAll(realTimeDatas);
List<MetricData> metricDatas = assetService.getMetricsByID(sensorId, startTime, duration);
TestCase.assertEquals(2, metricDatas.size());
for (MetricData sensordata : metricDatas) {
long metricTime = sensordata.getTimeStamp();
if (metricTime == startTime) {
TestCase.assertEquals(32.0, sensordata.getValueNum());
} else if (metricTime == startTime + 5 * 60 * 1000) {
TestCase.assertEquals(25.0, sensordata.getValueNum());
} else {
TestCase.fail();
}
}
assetRepository.deleteById(sensorId);
realtimeDataRepository.deleteById(tempRealTimeData.getId());
realtimeDataRepository.deleteById(realTimeData.getId());
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method getMetricsByID.
public List<MetricData> getMetricsByID(String assetID, Long starttime, Integer duration) {
// Check and get asset by ID
Asset asset = getAssetById(assetID);
// Get ValueUnits
Map<String, List<ValueUnit>> assetAndValueUnitsMap = new HashMap<String, List<ValueUnit>>();
switch(asset.getCategory()) {
case PDU:
// 1. Get all metric Data
assetAndValueUnitsMap = getPDURawMetrics(asset, starttime, duration);
// 3. Translate
return translateToMetricDataForPDU(assetAndValueUnitsMap, asset);
case Server:
// 1. Get all metric Data
assetAndValueUnitsMap = getServerRawMetrics(asset, starttime, duration);
// 2. Remove or filter
List<ValueUnit> serverHostUsageValueUnits = assetAndValueUnitsMap.get(assetID);
if (serverHostUsageValueUnits != null) {
removeServerUnusedMetrics(serverHostUsageValueUnits);
filterServerEneryConsumptionMetrics(serverHostUsageValueUnits, starttime);
}
// 3. Translate
return translateToMetricDataForServer(assetAndValueUnitsMap, asset);
default:
assetAndValueUnitsMap = getRawMetrics(asset, starttime, duration);
return translateToMetricDataForOtherAsset(assetAndValueUnitsMap, asset);
}
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method getValueUnitsByAssetID.
private List<ValueUnit> getValueUnitsByAssetID(String assetID, long starttime, int duration) {
List<RealTimeData> realtimeDatas = realtimeDataRepository.getDataByIDAndTimeRange(assetID, starttime, duration);
List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
if (realtimeDatas.isEmpty()) {
return valueunits;
}
for (RealTimeData realTimeData : realtimeDatas) {
for (ValueUnit value : realTimeData.getValues()) {
valueunits.add(value);
}
}
return valueunits;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method getServerMetricsDataById.
public List<MetricData> getServerMetricsDataById(String assetID, long starttime, int duration) {
Optional<Asset> serverAssetOptional = assetRepository.findById(assetID);
if (!serverAssetOptional.isPresent()) {
throw WormholeRequestException.NotFound("asset", "id", assetID);
}
Asset server = serverAssetOptional.get();
List<MetricData> result = new ArrayList<MetricData>();
Map<String, String> metricFormula = server.getMetricsformulars();
if (metricFormula == null || metricFormula.isEmpty()) {
return result;
}
result.addAll(getServerHostMetric(server, starttime, duration));
Map<String, String> justficationfileds = server.getJustificationfields();
String allPduPortInfo = justficationfileds.get(FlowgateConstant.PDU_PORT_FOR_SERVER);
List<String> pduPorts = null;
Map<String, String> pduAssetIdAndUsedOutletMap = null;
if (!StringUtils.isEmpty(allPduPortInfo)) {
pduPorts = Arrays.asList(allPduPortInfo.split(FlowgateConstant.SPILIT_FLAG));
pduAssetIdAndUsedOutletMap = new HashMap<String, String>();
for (String pduPortInfo : pduPorts) {
// startport_FIELDSPLIT_endDeviceName_FIELDSPLIT_endport_FIELDSPLIT_endDeviceAssetID
// item[0] start port
// item[1] device name
// item[2] end port
// itme[3] assetid
String[] items = pduPortInfo.split(FlowgateConstant.SEPARATOR);
pduAssetIdAndUsedOutletMap.put(items[3], items[2]);
}
}
String pduFormulasInfo = metricFormula.get(FlowgateConstant.PDU);
if (pduFormulasInfo != null) {
Map<String, Map<String, String>> pduMetrics = server.metricsFormulaToMap(pduFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
});
List<String> metricNames = new ArrayList<String>();
metricNames.add(MetricName.PDU_TOTAL_POWER);
metricNames.add(MetricName.PDU_APPARENT_POWER);
metricNames.add(MetricName.PDU_CURRENT);
metricNames.add(MetricName.PDU_VOLTAGE);
metricNames.add(MetricName.PDU_POWER_LOAD);
metricNames.add(MetricName.PDU_CURRENT_LOAD);
for (String pduId : pduMetrics.keySet()) {
List<RealTimeData> realtimedatas = realtimeDataRepository.getDataByIDAndTimeRange(pduId, starttime, duration);
List<ValueUnit> valueUnits = getValueUnits(realtimedatas, metricNames);
String outlet = UnknownOulet;
if (pduAssetIdAndUsedOutletMap != null) {
outlet = pduAssetIdAndUsedOutletMap.get(pduId);
}
result.addAll(generateServerPduMetricData(valueUnits, pduId, outlet));
}
}
String sensorFormulasInfo = metricFormula.get(FlowgateConstant.SENSOR);
if (sensorFormulasInfo != null) {
Map<String, Map<String, String>> sensorFormulars = server.metricsFormulaToMap(sensorFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
});
Map<String, List<RealTimeData>> assetIdAndRealtimeDataMap = new HashMap<String, List<RealTimeData>>();
for (Map.Entry<String, Map<String, String>> sensorFormula : sensorFormulars.entrySet()) {
Map<String, String> locationAndIdMap = sensorFormula.getValue();
String metricName = sensorFormula.getKey();
List<ValueUnit> valueUnits = generateSensorValueUnit(assetIdAndRealtimeDataMap, starttime, duration, locationAndIdMap, metricName);
result.addAll(generateServerSensorMetricData(valueUnits, metricName));
}
}
return result;
}
Aggregations