use of com.vmware.flowgate.common.model.RealTimeData 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.RealTimeData 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;
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetService method getOtherMetricsDataById.
private List<MetricData> getOtherMetricsDataById(String assetID, Long starttime, Integer duration) {
List<MetricData> metricDataList = new ArrayList<>();
List<RealTimeData> realTimeData = realtimeDataRepository.getDataByIDAndTimeRange(assetID, starttime, duration);
if (realTimeData == null || realTimeData.isEmpty()) {
return metricDataList;
}
RealTimeData latestData = findLatestData(realTimeData);
List<ValueUnit> latestDataValues = latestData.getValues();
if (latestDataValues == null || latestDataValues.isEmpty()) {
return metricDataList;
}
metricDataList.addAll(generateOtherMetricData(latestDataValues));
return metricDataList;
}
use of com.vmware.flowgate.common.model.RealTimeData in project flowgate by vmware.
the class AssetService method getServerHostMetric.
private List<MetricData> getServerHostMetric(Asset server, long starttime, int duration) {
List<MetricData> metricDataList = Lists.newArrayList();
String hostMetricsFormulaString = server.getMetricsformulars().get(FlowgateConstant.HOST_METRICS);
if (StringUtils.isBlank(hostMetricsFormulaString)) {
return metricDataList;
}
Map<String, String> hostMetricsFormula = server.metricsFormulaToMap(hostMetricsFormulaString, new TypeReference<Map<String, String>>() {
});
if (hostMetricsFormula == null || hostMetricsFormula.isEmpty()) {
return metricDataList;
}
Map<String, List<String>> assetIdAndMetricsNameList = Maps.newHashMap();
for (Map.Entry<String, String> itemEntry : hostMetricsFormula.entrySet()) {
List<String> metricsNameList = assetIdAndMetricsNameList.computeIfAbsent(itemEntry.getValue(), k -> Lists.newArrayList());
metricsNameList.add(itemEntry.getKey());
}
Map<String, List<RealTimeData>> realtimeDataMap = Maps.newHashMap();
for (Map.Entry<String, List<String>> entry : assetIdAndMetricsNameList.entrySet()) {
realtimeDataMap.put(entry.getKey(), realtimeDataRepository.getDataByIDAndTimeRange(entry.getKey(), starttime, duration));
}
Set<String> specialMetricNames = new HashSet<String>();
specialMetricNames.add(MetricName.SERVER_AVERAGE_USED_POWER);
specialMetricNames.add(MetricName.SERVER_PEAK_USED_POWER);
specialMetricNames.add(MetricName.SERVER_MINIMUM_USED_POWER);
specialMetricNames.add(MetricName.SERVER_ENERGY_CONSUMPTION);
specialMetricNames.add(MetricName.SERVER_AVERAGE_TEMPERATURE);
specialMetricNames.add(MetricName.SERVER_PEAK_TEMPERATURE);
MetricData metricData;
for (Map.Entry<String, List<RealTimeData>> realtimeDataEntry : realtimeDataMap.entrySet()) {
List<String> metricsNameList = assetIdAndMetricsNameList.get(realtimeDataEntry.getKey());
for (RealTimeData realTimeData : realtimeDataEntry.getValue()) {
for (ValueUnit valueUnit : realTimeData.getValues()) {
if (metricsNameList.contains(valueUnit.getKey())) {
metricData = new MetricData();
long timestamp = 0l;
String metricName = valueUnit.getKey();
String extraInfo = valueUnit.getExtraidentifier();
if (extraInfo == null && specialMetricNames.contains(metricName)) {
logger.error("The value of {} is invalid,RealtimeData Id: {}", metricName, realTimeData.getId());
continue;
}
switch(metricName) {
case MetricName.SERVER_AVERAGE_USED_POWER:
// Time of AvgPower is since time
timestamp = Long.valueOf(extraInfo);
break;
case MetricName.SERVER_PEAK_USED_POWER:
String[] sinceTimeAndPeakTime = extraInfo.split(FlowgateConstant.SEPARATOR);
if (sinceTimeAndPeakTime.length < TIMESTAMPARRAYLENGTH) {
logger.error("The extraInfo of {} is invalid,RealtimeData Id: {}", metricName, realTimeData.getId());
continue;
}
// Time of PeakPower is peakPower time
timestamp = Long.valueOf(sinceTimeAndPeakTime[1]);
break;
case MetricName.SERVER_MINIMUM_USED_POWER:
String[] sinceTimeAndMinimumTime = extraInfo.split(FlowgateConstant.SEPARATOR);
if (sinceTimeAndMinimumTime.length < TIMESTAMPARRAYLENGTH) {
logger.error("The extraInfo of {} is invalid,RealtimeData Id: {}", metricName, realTimeData.getId());
continue;
}
// Time of MinimumPower is minimumPower time
timestamp = Long.valueOf(sinceTimeAndMinimumTime[1]);
break;
case MetricName.SERVER_ENERGY_CONSUMPTION:
// Time of energy consumption is since time
timestamp = Long.valueOf(extraInfo);
break;
case MetricName.SERVER_AVERAGE_TEMPERATURE:
// Time of average temperature is since time
timestamp = Long.valueOf(extraInfo);
break;
case MetricName.SERVER_PEAK_TEMPERATURE:
// Time of energy consumption is since time
String[] temperatureSinceTimeAndPeakTime = extraInfo.split(FlowgateConstant.SEPARATOR);
if (temperatureSinceTimeAndPeakTime.length < TIMESTAMPARRAYLENGTH) {
logger.error("The extraInfo of {} is invalid,RealtimeData Id: {}", metricName, realTimeData.getId());
continue;
}
// Time of PeakTemperature is peak time
timestamp = Long.valueOf(temperatureSinceTimeAndPeakTime[1]);
break;
default:
// Time of other host metric is valueUnit current time
timestamp = valueUnit.getTime();
break;
}
metricData.setMetricName(valueUnit.getKey());
metricData.setTimeStamp(timestamp);
metricData.setValue(valueUnit.getValue());
metricData.setValueNum(valueUnit.getValueNum());
// This kind of logic will be deprecated in next version
String unit = databaseUnitAndOutputUnitMap.get(valueUnit.getUnit());
if (unit == null) {
unit = valueUnit.getUnit();
}
metricData.setUnit(unit);
metricDataList.add(metricData);
}
}
}
}
return metricDataList;
}
Aggregations