use of com.vmware.flowgate.common.model.ValueUnit 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.ValueUnit in project flowgate by vmware.
the class AssetService method generateMetricsDataForPDU.
private List<MetricData> generateMetricsDataForPDU(List<ValueUnit> valueunits) {
List<MetricData> result = new ArrayList<MetricData>();
for (ValueUnit valueunit : valueunits) {
MetricData metricData = new MetricData();
metricData.setTimeStamp(valueunit.getTime());
metricData.setValue(valueunit.getValue());
metricData.setValueNum(valueunit.getValueNum());
String unit = databaseUnitAndOutputUnitMap.get(valueunit.getUnit());
if (unit == null) {
unit = valueunit.getUnit();
}
metricData.setUnit(unit);
String extraidentifier = valueunit.getExtraidentifier();
switch(valueunit.getKey()) {
case MetricName.PDU_ACTIVE_POWER:
// PDU|INLET:1|ActivePower
metricData.setMetricName(String.format(MetricName.PDU_XLET_ACTIVE_POWER, extraidentifier));
result.add(metricData);
break;
case MetricName.PDU_APPARENT_POWER:
metricData.setMetricName(String.format(MetricName.PDU_XLET_APPARENT_POWER, extraidentifier));
result.add(metricData);
break;
case MetricName.PDU_CURRENT:
if (extraidentifier != null) {
String[] extraidentifierList = extraidentifier.split("\\|");
if (extraidentifierList.length == 1) {
metricData.setMetricName(String.format(MetricName.PDU_XLET_CURRENT, extraidentifier));
} else if (extraidentifierList.length == 2) {
String inlet = extraidentifierList[0];
String pole = extraidentifierList[1];
metricData.setMetricName(String.format(MetricName.PDU_INLET_XPOLE_CURRENT, inlet, pole));
}
result.add(metricData);
} else {
metricData.setMetricName(MetricName.PDU_TOTAL_CURRENT);
result.add(metricData);
}
break;
case MetricName.PDU_VOLTAGE:
if (extraidentifier != null) {
String[] extraidentifierList = extraidentifier.split("\\|");
if (extraidentifierList.length == 1) {
metricData.setMetricName(String.format(MetricName.PDU_XLET_VOLTAGE, extraidentifier));
} else if (extraidentifierList.length == 2) {
String inlet = extraidentifierList[0];
String pole = extraidentifierList[1];
metricData.setMetricName(String.format(MetricName.PDU_INLET_XPOLE_VOLTAGE, inlet, pole));
}
result.add(metricData);
}
break;
case MetricName.PDU_FREE_CAPACITY:
if (extraidentifier != null) {
String[] extraidentifierList = extraidentifier.split("\\|");
if (extraidentifierList.length == 1) {
metricData.setMetricName(String.format(MetricName.PDU_XLET_FREE_CAPACITY, extraidentifier));
} else if (extraidentifierList.length == 2) {
String inlet = extraidentifierList[0];
String pole = extraidentifierList[1];
metricData.setMetricName(String.format(MetricName.PDU_INLET_XPOLE_FREE_CAPACITY, inlet, pole));
}
result.add(metricData);
}
break;
case MetricName.PDU_CURRENT_LOAD:
metricData.setMetricName(MetricName.PDU_CURRENT_LOAD);
result.add(metricData);
break;
case MetricName.PDU_POWER_LOAD:
metricData.setMetricName(MetricName.PDU_POWER_LOAD);
result.add(metricData);
break;
case MetricName.PDU_TOTAL_POWER:
metricData.setMetricName(MetricName.PDU_TOTAL_POWER);
result.add(metricData);
break;
case MetricName.PDU_HUMIDITY:
metricData.setMetricName(String.format(MetricKeyName.PDU_HUMIDITY_LOCATIONX, extraidentifier));
result.add(metricData);
break;
case MetricName.PDU_TEMPERATURE:
metricData.setMetricName(String.format(MetricKeyName.PDU_TEMPERATURE_LOCATIONX, extraidentifier));
result.add(metricData);
break;
default:
break;
}
}
return result;
}
use of com.vmware.flowgate.common.model.ValueUnit 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;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method translateToMetricDataForServer.
private List<MetricData> translateToMetricDataForServer(Map<String, List<ValueUnit>> assetAndValueUnitsMap, Asset asset) {
List<MetricData> metricDatas = new ArrayList<MetricData>();
Map<String, Map<String, String>> displayNameAndFormulasMap = getMetricDispalyNameAndFormulaMapForServer(asset);
if (displayNameAndFormulasMap.isEmpty() || !displayNameAndFormulasMap.containsKey(DISPLAYNAMEANDFORMULANAMEMAPKEY)) {
return metricDatas;
}
// The displayNameAndFormulaKeyMap use to find a method to translate the valueUnit to MetricData
Map<String, String> displayNameAndFormulaKeyMap = displayNameAndFormulasMap.get(DISPLAYNAMEANDFORMULANAMEMAPKEY);
displayNameAndFormulasMap.remove(DISPLAYNAMEANDFORMULANAMEMAPKEY);
CompareValueUnitByTime comparator = new CompareValueUnitByTime();
// For server-voltage, the server voltage is the server-connected-pdu-outlet voltage
// If the Outlet voltage is null, use the inlet voltage
// If the server asset has multiple pdus, only use one of these pdus
Map<String, List<ValueUnit>> serverVoltageIdAndValues = new HashMap<String, List<ValueUnit>>();
List<ValueUnit> serverVoltages = null;
String serverVoltageFormula = null;
for (Map.Entry<String, Map<String, String>> displayNameAndFormulaEntry : displayNameAndFormulasMap.entrySet()) {
String displayName = displayNameAndFormulaEntry.getKey();
Map<String, String> valueUnitNameAndFormulaMap = displayNameAndFormulaEntry.getValue();
// Key:MetricName Value:Formula
if (displayName.equals(MetricName.SERVER_VOLTAGE)) {
serverVoltageFormula = new ArrayList<String>(valueUnitNameAndFormulaMap.values()).get(0);
continue;
}
for (Map.Entry<String, String> valueUnitNameAndFormula : valueUnitNameAndFormulaMap.entrySet()) {
String valueUnitName = valueUnitNameAndFormula.getKey();
String formula = valueUnitNameAndFormula.getValue();
String[] ids = formula.split("\\+|-|\\*|/|\\(|\\)");
Map<String, List<ValueUnit>> idAndValues = new HashMap<>();
for (String id : ids) {
List<ValueUnit> inletVoltages = null;
List<ValueUnit> outletVoltages = null;
if (displayName.contains(FlowgateConstant.OUTLET_NAME_PREFIX) && MetricName.PDU_VOLTAGE.equals(valueUnitName)) {
inletVoltages = new ArrayList<ValueUnit>();
outletVoltages = new ArrayList<ValueUnit>();
}
List<ValueUnit> valueUnits = new ArrayList<ValueUnit>();
if (!assetAndValueUnitsMap.containsKey(id)) {
continue;
}
for (ValueUnit valueUnit : assetAndValueUnitsMap.get(id)) {
if (!valueUnitName.equals(valueUnit.getKey())) {
continue;
}
String extraidentifier = valueUnit.getExtraidentifier();
String outlet = null;
switch(valueUnitName) {
case MetricName.PDU_CURRENT:
// PDU:23551d6dacf2432c8a3edbc6bbc922cd|OUTLET:1|Current
if (displayName.contains(FlowgateConstant.OUTLET_NAME_PREFIX) && extraidentifier != null) {
outlet = displayName.split("\\|")[1];
if (outlet.equals(extraidentifier)) {
valueUnits.add(valueUnit);
}
}
// PDU:23551d6dacf2432c8a3edbc6bbc922cd|Current
if (!displayName.contains(FlowgateConstant.OUTLET_NAME_PREFIX)) {
if (extraidentifier == null) {
// PDU current
valueUnits.add(valueUnit);
}
}
break;
case MetricName.PDU_APPARENT_POWER:
// Sample value of displayName: PDU:23551d6dacf2432c8a3edbc6bbc922cd|OUTLET:1|Power
outlet = displayName.split("\\|")[1];
if (outlet.equals(extraidentifier)) {
valueUnits.add(valueUnit);
}
break;
case // valueunitName
MetricName.PDU_VOLTAGE:
// DisplayName: PDU:23551d6dacf2432c8a3edbc6bbc922cd|OUTLET:1|Voltage
if (extraidentifier == null) {
continue;
} else {
outlet = displayName.split("\\|")[1];
if (outlet.equals(extraidentifier)) {
outletVoltages.add(valueUnit);
} else if (extraidentifier.indexOf(FlowgateConstant.INLET_NAME_PREFIX) > 0) {
inletVoltages.add(valueUnit);
}
}
break;
case // Power
MetricName.SERVER_POWER:
if (MetricName.SERVER_POWER.equals(displayName)) {
// When the displayName is Power,the valueUnits is only from server_Host_metrics
// Sample value of displayName: Power
valueUnits.add(valueUnit);
} else {
// Sample value of displayName: PDU:23551d6dacf2432c8a3edbc6bbc922cd|Power
if (extraidentifier == null) {
valueUnits.add(valueUnit);
}
}
break;
default:
valueUnits.add(valueUnit);
break;
}
}
if (displayName.contains(FlowgateConstant.OUTLET_NAME_PREFIX) && MetricName.PDU_VOLTAGE.equals(valueUnitName)) {
valueUnits = outletVoltages;
if (serverVoltages == null || serverVoltages.isEmpty()) {
if (outletVoltages.isEmpty()) {
if (inletVoltages.isEmpty()) {
continue;
}
outletVoltages = inletVoltages;
}
serverVoltages = outletVoltages;
if (serverVoltages.isEmpty()) {
continue;
}
serverVoltageIdAndValues.put(id, serverVoltages);
}
}
if (valueUnits.isEmpty()) {
continue;
}
Collections.sort(valueUnits, comparator);
idAndValues.put(id, valueUnits);
}
if (!idAndValues.isEmpty()) {
// <id,valueUnits>
Function<TranslateContext, MetricData> function = TranslateFunctionService.convert;
String formulaKey = displayNameAndFormulaKeyMap.get(displayName);
if (TranslateFunctionService.serverFormulaKeyAndFunction.containsKey(formulaKey)) {
function = TranslateFunctionService.serverFormulaKeyAndFunction.get(formulaKey);
}
metricDatas.addAll(convertValueUnitToMetricData(displayName, function, formula, idAndValues));
}
}
}
if (!serverVoltageIdAndValues.isEmpty()) {
Function<TranslateContext, MetricData> function = TranslateFunctionService.convert;
String formulaKey = displayNameAndFormulaKeyMap.get(MetricName.SERVER_VOLTAGE);
if (TranslateFunctionService.serverFormulaKeyAndFunction.containsKey(formulaKey)) {
function = TranslateFunctionService.serverFormulaKeyAndFunction.get(formulaKey);
}
metricDatas.addAll(convertValueUnitToMetricData(MetricName.SERVER_VOLTAGE, function, serverVoltageFormula, serverVoltageIdAndValues));
}
return metricDatas;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method filterServerEneryConsumptionMetrics.
private void filterServerEneryConsumptionMetrics(List<ValueUnit> valueUnits, long startTime) {
Iterator<ValueUnit> ite = valueUnits.iterator();
List<ValueUnit> eneryConsumptions = new ArrayList<ValueUnit>();
while (ite.hasNext()) {
ValueUnit valueUnit = ite.next();
if (MetricName.SERVER_ENERGY_CONSUMPTION.equals(valueUnit.getKey())) {
eneryConsumptions.add(valueUnit);
ite.remove();
}
}
if (eneryConsumptions.isEmpty()) {
return;
}
eneryConsumptions = filterServerEnergyConsumption(eneryConsumptions, startTime);
valueUnits.addAll(eneryConsumptions);
}
Aggregations