use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method filterServerEnergyConsumptionBySinceTime.
private void filterServerEnergyConsumptionBySinceTime(List<ValueUnit> valueUnits, long startTime) {
Iterator<ValueUnit> ite = valueUnits.iterator();
while (ite.hasNext()) {
ValueUnit valueUnit = ite.next();
long sinceTime = Long.parseLong(valueUnit.getExtraidentifier());
if (sinceTime < startTime) {
ite.remove();
}
}
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class AssetService method removeServerUnusedMetrics.
private void removeServerUnusedMetrics(List<ValueUnit> valueUnits) {
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_AVERAGE_TEMPERATURE);
specialMetricNames.add(MetricName.SERVER_PEAK_TEMPERATURE);
Iterator<ValueUnit> ite = valueUnits.iterator();
while (ite.hasNext()) {
ValueUnit valueUnit = ite.next();
if (specialMetricNames.contains(valueUnit.getKey())) {
ite.remove();
}
}
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class NlyteDataService method generateValueUnits.
public List<ValueUnit> generateValueUnits(List<PowerStripsRealtimeValue> values, HashMap<AdvanceSettingType, String> advanceSettingMap) {
List<ValueUnit> valueunits = new ArrayList<ValueUnit>();
long currenttime = System.currentTimeMillis();
String dateFormat = advanceSettingMap.get(AdvanceSettingType.DateFormat);
String timezone = advanceSettingMap.get(AdvanceSettingType.TimeZone);
String current = advanceSettingMap.get(AdvanceSettingType.PDU_AMPS_UNIT);
String power = advanceSettingMap.get(AdvanceSettingType.PDU_POWER_UNIT);
String voltage = advanceSettingMap.get(AdvanceSettingType.PDU_VOLT_UNIT);
for (PowerStripsRealtimeValue value : values) {
String valueDateTime = value.getRecordedDateTime();
long recordedTime = WormholeDateFormat.getLongTime(valueDateTime, dateFormat, timezone);
if (recordedTime > currenttime || recordedTime == -1) {
logger.error("Failed to translate the time string: " + valueDateTime);
continue;
}
if (sensorValueTypeMap.containsKey(value.getName())) {
ValueUnit valueunit = new ValueUnit();
valueunit.setKey(sensorValueTypeMap.get(value.getName()));
String unit = value.getUnit();
MetricUnit targetUnit = null, sourceUnit = null;
switch(sensorValueTypeMap.get(value.getName())) {
case MetricName.PDU_TOTAL_CURRENT:
if (unit != null && !unit.isEmpty()) {
sourceUnit = MetricUnit.valueOf(unit.toUpperCase());
} else {
sourceUnit = MetricUnit.valueOf(current.toUpperCase());
}
targetUnit = MetricUnit.A;
break;
case MetricName.PDU_TOTAL_POWER:
if (unit != null && !unit.isEmpty()) {
sourceUnit = MetricUnit.valueOf(unit.toUpperCase());
} else {
sourceUnit = MetricUnit.valueOf(power.toUpperCase());
}
targetUnit = MetricUnit.kW;
break;
case MetricName.PDU_VOLTAGE:
if (unit != null && !unit.isEmpty()) {
sourceUnit = MetricUnit.valueOf(unit.toUpperCase());
} else {
sourceUnit = MetricUnit.valueOf(voltage.toUpperCase());
}
targetUnit = MetricUnit.V;
break;
default:
break;
}
valueunit.setUnit(targetUnit.toString());
try {
valueunit.setValueNum(valueunit.translateUnit(value.getValue(), sourceUnit, targetUnit));
} catch (WormholeException e) {
logger.error("Cannot translate Unit", e);
}
valueunit.setTime(recordedTime);
valueunits.add(valueunit);
} else {
continue;
}
}
return valueunits;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class PowerIQService method getValueUnits.
public List<ValueUnit> getValueUnits(Map<String, String> pduInfoFromPowerIQ, PowerIQAPIClient client, HashMap<AdvanceSettingType, String> advanceSettingMap) {
List<ValueUnit> values = new ArrayList<ValueUnit>();
Long pduId = Long.parseLong(pduInfoFromPowerIQ.get(FlowgateConstant.PDU_ID_FROM_POWERIQ));
List<Outlet> outlets = client.getOutlets(pduId);
Pdu pdu = client.getPduByID(pduId);
if (outlets.isEmpty() && pdu.getReading() == null) {
return values;
}
String dateFormat = advanceSettingMap.get(AdvanceSettingType.DateFormat);
String timezone = advanceSettingMap.get(AdvanceSettingType.TimeZone);
String PDU_AMPS_UNIT = advanceSettingMap.get(AdvanceSettingType.PDU_AMPS_UNIT);
String PDU_POWER_UNIT = advanceSettingMap.get(AdvanceSettingType.PDU_POWER_UNIT);
String PDU_VOLT_UNIT = advanceSettingMap.get(AdvanceSettingType.PDU_VOLT_UNIT);
if (PDU_AMPS_UNIT == null) {
// By default the Current unit in powerIQ is Amps.
PDU_AMPS_UNIT = POWERIQ_CURRENT_UNIT;
}
if (PDU_POWER_UNIT == null) {
// By default the active_power unit in powerIQ is watt.
PDU_POWER_UNIT = POWERIQ_POWER_UNIT;
}
if (PDU_VOLT_UNIT == null) {
// By default the voltage unit in powerIQ is volt.
PDU_VOLT_UNIT = POWERIQ_VOLTAGE_UNIT;
}
double inlteTotalPower = 0.0;
double inletTotalCurrent = 0.0;
double inletVoltage = 0.0;
Reading pduReading = pdu.getReading();
List<InletReading> inletReadings = null;
List<InletPoleReading> inletPoleReadings = null;
if (pduReading != null) {
inletReadings = pduReading.getInletReadings();
inletPoleReadings = pduReading.getInletPoleReadings();
}
if (inletReadings != null && !inletReadings.isEmpty()) {
String time = null;
for (InletReading inletReading : inletReadings) {
time = inletReading.getReadingTime();
if (time != null) {
break;
}
}
long valueTime = -1;
if (time != null) {
valueTime = WormholeDateFormat.getLongTime(time, dateFormat, timezone);
}
if (valueTime == -1) {
logger.error("Failed to translate the time string: " + time + ".And the dateformat is " + dateFormat);
} else {
for (InletReading reading : inletReadings) {
String extraIdentifier = FlowgateConstant.INLET_NAME_PREFIX + reading.getInletOrdinal();
Double voltage = reading.getVoltage();
if (voltage != null) {
ValueUnit voltageValue = new ValueUnit();
voltageValue.setExtraidentifier(extraIdentifier);
voltageValue.setKey(MetricName.PDU_VOLTAGE);
voltageValue.setTime(valueTime);
voltageValue.setValueNum(voltageValue.translateUnit(voltage, MetricUnit.valueOf(PDU_VOLT_UNIT), MetricUnit.V));
voltageValue.setUnit(MetricUnit.V.toString());
values.add(voltageValue);
inletVoltage = voltageValue.getValueNum();
}
Double current = reading.getCurrent();
if (current != null) {
ValueUnit currentValue = new ValueUnit();
currentValue.setExtraidentifier(extraIdentifier);
currentValue.setKey(MetricName.PDU_CURRENT);
currentValue.setTime(valueTime);
currentValue.setValueNum(currentValue.translateUnit(current, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
currentValue.setUnit(MetricUnit.A.toString());
values.add(currentValue);
inletTotalCurrent += currentValue.getValueNum();
}
Double activePower = reading.getActivePower();
if (activePower != null) {
ValueUnit activePowerValue = new ValueUnit();
activePowerValue.setExtraidentifier(extraIdentifier);
activePowerValue.setKey(MetricName.PDU_ACTIVE_POWER);
activePowerValue.setTime(valueTime);
activePowerValue.setValueNum(activePowerValue.translateUnit(activePower, MetricUnit.valueOf(PDU_POWER_UNIT), MetricUnit.kW));
activePowerValue.setUnit(MetricUnit.kW.toString());
values.add(activePowerValue);
}
Double apparentPower = reading.getApparentPower();
if (apparentPower != null) {
ValueUnit apparentPowerValue = new ValueUnit();
apparentPowerValue.setExtraidentifier(extraIdentifier);
apparentPowerValue.setKey(MetricName.PDU_APPARENT_POWER);
apparentPowerValue.setTime(valueTime);
apparentPowerValue.setValueNum(apparentPowerValue.translateUnit(apparentPower, MetricUnit.valueOf(PDU_POWER_UNIT), MetricUnit.kW));
apparentPowerValue.setUnit(MetricUnit.kW.toString());
values.add(apparentPowerValue);
inlteTotalPower += apparentPowerValue.getValueNum();
}
Double freeCapacity = reading.getUnutilizedCapacity();
if (freeCapacity != null) {
ValueUnit freeCapacityValue = new ValueUnit();
freeCapacityValue.setExtraidentifier(extraIdentifier);
freeCapacityValue.setKey(MetricName.PDU_FREE_CAPACITY);
freeCapacityValue.setTime(valueTime);
freeCapacityValue.setValueNum(freeCapacityValue.translateUnit(freeCapacity, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
freeCapacityValue.setUnit(MetricUnit.A.toString());
values.add(freeCapacityValue);
}
}
ValueUnit total_current = new ValueUnit();
total_current.setKey(MetricName.PDU_TOTAL_CURRENT);
total_current.setTime(valueTime);
total_current.setUnit(MetricUnit.A.toString());
total_current.setValueNum(inletTotalCurrent);
values.add(total_current);
ValueUnit total_power = new ValueUnit();
total_power.setKey(MetricName.PDU_TOTAL_POWER);
total_power.setTime(valueTime);
total_power.setUnit(MetricUnit.kW.toString());
total_power.setValueNum(inlteTotalPower);
values.add(total_power);
}
}
if (inletPoleReadings != null && !inletPoleReadings.isEmpty()) {
String inletPoleReadingTime = null;
for (InletPoleReading inletPoleReading : inletPoleReadings) {
inletPoleReadingTime = inletPoleReading.getReadingTime();
if (inletPoleReadingTime != null) {
break;
}
}
long valueTime = -1;
if (inletPoleReadingTime != null) {
valueTime = WormholeDateFormat.getLongTime(inletPoleReadingTime, dateFormat, timezone);
}
if (valueTime == -1) {
logger.error("Failed to translate the time string: " + inletPoleReadingTime + ".And the dateformat is " + dateFormat);
} else {
for (InletPoleReading reading : inletPoleReadings) {
String extraIdentifier = FlowgateConstant.INLET_NAME_PREFIX + reading.getInletOrdinal() + FlowgateConstant.INLET_POLE_NAME_PREFIX + reading.getInletPoleOrdinal();
Double currentValue = reading.getCurrent();
if (currentValue != null) {
ValueUnit current = new ValueUnit();
current.setExtraidentifier(extraIdentifier);
current.setKey(MetricName.PDU_CURRENT);
current.setTime(valueTime);
current.setValueNum(current.translateUnit(currentValue, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
current.setUnit(MetricUnit.A.toString());
values.add(current);
}
Double voltageValue = reading.getVoltage();
if (voltageValue != null) {
ValueUnit voltage = new ValueUnit();
voltage.setExtraidentifier(extraIdentifier);
voltage.setKey(MetricName.PDU_VOLTAGE);
voltage.setTime(valueTime);
voltage.setValueNum(voltage.translateUnit(voltageValue, MetricUnit.valueOf(PDU_VOLT_UNIT), MetricUnit.V));
voltage.setUnit(MetricUnit.V.toString());
values.add(voltage);
}
Double freeCapacityValue = reading.getUnutilizedCapacity();
if (freeCapacityValue != null) {
ValueUnit freeCapacity = new ValueUnit();
freeCapacity.setExtraidentifier(extraIdentifier);
freeCapacity.setKey(MetricName.PDU_FREE_CAPACITY);
freeCapacity.setTime(valueTime);
freeCapacity.setValueNum(freeCapacity.translateUnit(freeCapacityValue, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
freeCapacity.setUnit(MetricUnit.A.toString());
values.add(freeCapacity);
}
}
}
}
if (!outlets.isEmpty()) {
String time = null;
for (Outlet outlet : outlets) {
time = outlet.getReading().getReadingTime();
if (time != null) {
break;
}
}
long valueTime = -1;
if (time != null) {
valueTime = WormholeDateFormat.getLongTime(time, dateFormat, timezone);
}
if (valueTime == -1) {
logger.error("Failed to translate the time string: " + time + ".And the dateformat is " + dateFormat);
} else {
double totalOutletCurrentUsed = 0.0;
double totalOutletPowerUsed = 0.0;
for (Outlet outlet : outlets) {
OutletReading reading = outlet.getReading();
String extraIdentifier = FlowgateConstant.OUTLET_NAME_PREFIX + outlet.getOrdinal();
Double voltage = reading.getVoltage();
if (voltage != null) {
ValueUnit voltageValue = new ValueUnit();
voltageValue.setExtraidentifier(extraIdentifier);
voltageValue.setKey(MetricName.PDU_VOLTAGE);
voltageValue.setTime(valueTime);
voltageValue.setValueNum(voltageValue.translateUnit(voltage, MetricUnit.valueOf(PDU_VOLT_UNIT), MetricUnit.V));
voltageValue.setUnit(MetricUnit.V.toString());
values.add(voltageValue);
}
Double current = reading.getCurrent();
if (current != null) {
ValueUnit currentValue = new ValueUnit();
currentValue.setExtraidentifier(extraIdentifier);
currentValue.setKey(MetricName.PDU_CURRENT);
currentValue.setTime(valueTime);
currentValue.setValueNum(currentValue.translateUnit(current, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
currentValue.setUnit(MetricUnit.A.toString());
values.add(currentValue);
totalOutletCurrentUsed += currentValue.getValueNum();
}
Double active_power = reading.getActivePower();
if (active_power != null) {
ValueUnit activePowerValue = new ValueUnit();
activePowerValue.setExtraidentifier(extraIdentifier);
activePowerValue.setKey(MetricName.PDU_ACTIVE_POWER);
activePowerValue.setTime(valueTime);
activePowerValue.setValueNum(activePowerValue.translateUnit(active_power, MetricUnit.valueOf(PDU_POWER_UNIT), MetricUnit.kW));
activePowerValue.setUnit(MetricUnit.kW.toString());
values.add(activePowerValue);
}
Double apparent_power = reading.getApparentPower();
if (apparent_power != null) {
ValueUnit apparentPowerValue = new ValueUnit();
apparentPowerValue.setExtraidentifier(extraIdentifier);
apparentPowerValue.setKey(MetricName.PDU_APPARENT_POWER);
apparentPowerValue.setTime(valueTime);
apparentPowerValue.setValueNum(apparentPowerValue.translateUnit(apparent_power, MetricUnit.valueOf(PDU_POWER_UNIT), MetricUnit.kW));
apparentPowerValue.setUnit(MetricUnit.kW.toString());
values.add(apparentPowerValue);
totalOutletPowerUsed += apparentPowerValue.getValueNum();
}
Double freeCapacity = reading.getUnutilizedCapacity();
if (freeCapacity != null) {
ValueUnit freeCapacityValue = new ValueUnit();
freeCapacityValue.setExtraidentifier(extraIdentifier);
freeCapacityValue.setKey(MetricName.PDU_FREE_CAPACITY);
freeCapacityValue.setTime(valueTime);
freeCapacityValue.setValueNum(freeCapacityValue.translateUnit(freeCapacity, MetricUnit.valueOf(PDU_AMPS_UNIT), MetricUnit.A));
freeCapacityValue.setUnit(MetricUnit.A.toString());
values.add(freeCapacityValue);
}
}
String rate_current = pduInfoFromPowerIQ.get(FlowgateConstant.PDU_RATE_AMPS);
DecimalFormat df = new DecimalFormat("#.0000");
if (totalOutletCurrentUsed == 0.0) {
totalOutletCurrentUsed = inletTotalCurrent;
}
if (rate_current != null) {
Double rate_current_value = Double.parseDouble(rate_current);
ValueUnit current_load = new ValueUnit();
current_load.setKey(MetricName.PDU_CURRENT_LOAD);
current_load.setTime(valueTime);
current_load.setUnit(MetricUnit.percent.toString());
current_load.setValueNum(Double.parseDouble(df.format(totalOutletCurrentUsed / rate_current_value)));
values.add(current_load);
}
String real_rate_power = getRealRatePower(inletVoltage, pduInfoFromPowerIQ);
if (totalOutletPowerUsed == 0.0) {
totalOutletPowerUsed = inlteTotalPower;
}
if (real_rate_power != null) {
Double rate_power_value = Double.parseDouble(real_rate_power);
ValueUnit power_load = new ValueUnit();
power_load.setKey(MetricName.PDU_POWER_LOAD);
power_load.setTime(valueTime);
power_load.setUnit(MetricUnit.percent.toString());
power_load.setValueNum(Double.parseDouble(df.format(totalOutletPowerUsed / rate_power_value)));
values.add(power_load);
}
}
}
return values;
}
use of com.vmware.flowgate.common.model.ValueUnit in project flowgate by vmware.
the class PowerIQService method getRealTimeDatas.
public List<RealTimeData> getRealTimeDatas(Map<String, Map<String, String>> pduAssetIdAndPduInfoMap, PowerIQAPIClient client, HashMap<AdvanceSettingType, String> advanceSettingMap) {
List<RealTimeData> realTimeDatas = new ArrayList<RealTimeData>();
if (pduAssetIdAndPduInfoMap == null || pduAssetIdAndPduInfoMap.isEmpty()) {
return realTimeDatas;
}
try {
for (Map.Entry<String, Map<String, String>> map : pduAssetIdAndPduInfoMap.entrySet()) {
List<ValueUnit> values = getValueUnits(map.getValue(), client, advanceSettingMap);
if (!values.isEmpty()) {
RealTimeData realTimeData = new RealTimeData();
realTimeData.setAssetID(map.getKey());
realTimeData.setValues(values);
realTimeData.setTime(values.get(0).getTime());
// this will remove the duplicated items.
realTimeData.setId(map.getKey() + "_" + realTimeData.getTime());
realTimeDatas.add(realTimeData);
} else {
continue;
}
}
} catch (Exception e) {
logger.error("An exception occurred in the method of getRealTimeDatas from SyncPowerIQRealTimeDataJob", e);
}
return realTimeDatas;
}
Aggregations