Search in sources :

Example 1 with MetricUnit

use of com.vmware.flowgate.common.model.ValueUnit.MetricUnit in project flowgate by vmware.

the class OpenManageJobService method getMetricsData.

private Map<String, ValueUnit> getMetricsData(String deviceId, OpenManageAPIClient client, Plugin powerManage) {
    DevicePower powerMetricsData = client.getDevicePowerMetrics(deviceId);
    long currentTime = 0;
    Map<String, ValueUnit> metricNameAndValueUnitMap = new HashMap<String, ValueUnit>();
    // Power metrics data from the Openmanage base API
    if (powerMetricsData != null && CIM.equals(powerMetricsData.getDateFormat())) {
        String power = powerMetricsData.getPower();
        if (!NULLVALUE.equals(power)) {
            ValueUnit instantPower = new ValueUnit();
            currentTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getInstantaneousHeadroomTimeStamp());
            instantPower.setKey(MetricName.SERVER_POWER);
            instantPower.setTime(currentTime);
            instantPower.setUnit(MetricUnit.kW.name());
            instantPower.setValueNum(instantPower.translateUnit(Double.valueOf(power), metricUnitMap.get(powerMetricsData.getPowerUnit()), MetricUnit.kW));
            metricNameAndValueUnitMap.put(MetricName.SERVER_POWER, instantPower);
        }
        long sinceTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getSince());
        String energyConsumption = powerMetricsData.getSystemEnergyConsumption();
        if (!NULLVALUE.equals(energyConsumption)) {
            long systemEnergyConsumptionTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getSystemEnergyConsumptionTimeStamp());
            ValueUnit systemEnergyConsumption = new ValueUnit();
            systemEnergyConsumption.setTime(systemEnergyConsumptionTime);
            systemEnergyConsumption.setExtraidentifier(String.valueOf(sinceTime));
            systemEnergyConsumption.setKey(MetricName.SERVER_ENERGY_CONSUMPTION);
            systemEnergyConsumption.setUnit(MetricUnit.kWh.name());
            systemEnergyConsumption.setValueNum(systemEnergyConsumption.translateUnit(Double.valueOf(energyConsumption), metricUnitMap.get(powerMetricsData.getSystemEnergyConsumptionUnit()), MetricUnit.kWh));
            metricNameAndValueUnitMap.put(MetricName.SERVER_ENERGY_CONSUMPTION, systemEnergyConsumption);
        }
        String avgValue = powerMetricsData.getAvgPower();
        if (!NULLVALUE.equals(avgValue)) {
            ValueUnit avgPower = new ValueUnit();
            avgPower.setTime(currentTime);
            avgPower.setExtraidentifier(String.valueOf(sinceTime));
            avgPower.setKey(MetricName.SERVER_AVERAGE_USED_POWER);
            avgPower.setUnit(MetricUnit.kW.name());
            avgPower.setValueNum(avgPower.translateUnit(Double.valueOf(avgValue), metricUnitMap.get(powerMetricsData.getAvgPowerUnit()), MetricUnit.kW));
            metricNameAndValueUnitMap.put(MetricName.SERVER_AVERAGE_USED_POWER, avgPower);
        }
        String peakValue = powerMetricsData.getPeakPower();
        if (!NULLVALUE.equals(peakValue)) {
            ValueUnit peakPower = new ValueUnit();
            peakPower.setTime(currentTime);
            long peakPowerTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getPeakPowerTimeStamp());
            String sinceAndPeakTime = String.valueOf(sinceTime) + FlowgateConstant.SEPARATOR + String.valueOf(peakPowerTime);
            // Record the since time and peak power time, for example  1612417403074_FIELDSPLIT_1612415606985
            peakPower.setExtraidentifier(sinceAndPeakTime);
            peakPower.setKey(MetricName.SERVER_PEAK_USED_POWER);
            peakPower.setUnit(MetricUnit.kW.name());
            peakPower.setValueNum(peakPower.translateUnit(Double.valueOf(peakValue), metricUnitMap.get(powerMetricsData.getPeakPowerUnit()), MetricUnit.kW));
            metricNameAndValueUnitMap.put(MetricName.SERVER_PEAK_USED_POWER, peakPower);
        }
        String minimumValue = powerMetricsData.getMinimumPower();
        if (!NULLVALUE.equals(minimumValue)) {
            ValueUnit minimumPower = new ValueUnit();
            minimumPower.setTime(currentTime);
            long minimumTime = WormholeDateFormat.cimDateToMilliseconds(powerMetricsData.getMinimumPowerTimeStamp());
            String sinceAndMinimum = String.valueOf(sinceTime) + FlowgateConstant.SEPARATOR + String.valueOf(minimumTime);
            minimumPower.setExtraidentifier(sinceAndMinimum);
            minimumPower.setKey(MetricName.SERVER_MINIMUM_USED_POWER);
            minimumPower.setUnit(MetricUnit.kW.name());
            minimumPower.setValueNum(minimumPower.translateUnit(Double.valueOf(minimumValue), metricUnitMap.get(powerMetricsData.getPeakPowerUnit()), MetricUnit.kW));
            metricNameAndValueUnitMap.put(MetricName.SERVER_MINIMUM_USED_POWER, minimumPower);
        }
    }
    // Temperature metrics data from the Openmanage base API
    DeviceTemperature temperatureMetrics = client.getDeviceTemperatureMetrics(deviceId);
    if (temperatureMetrics != null && CIM.equals(temperatureMetrics.getDateFormat())) {
        String temperatureValue = temperatureMetrics.getInstantaneousTemperature();
        if (!NULLVALUE.equals(temperatureValue)) {
            ValueUnit temperature = new ValueUnit();
            temperature.setKey(MetricName.SERVER_TEMPERATURE);
            temperature.setTime(currentTime);
            temperature.setUnit(MetricUnit.C.name());
            temperature.setValueNum(temperature.translateUnit(Double.valueOf(temperatureValue), metricUnitMap.get(temperatureMetrics.getInstantaneousTemperatureUnit()), MetricUnit.C));
            metricNameAndValueUnitMap.put(MetricName.SERVER_TEMPERATURE, temperature);
        }
        long startTime = WormholeDateFormat.cimDateToMilliseconds(temperatureMetrics.getStartTime());
        String avgValue = temperatureMetrics.getAvgTemperature();
        if (!NULLVALUE.equals(avgValue)) {
            ValueUnit avgTemperature = new ValueUnit();
            avgTemperature.setKey(MetricName.SERVER_AVERAGE_TEMPERATURE);
            avgTemperature.setExtraidentifier(String.valueOf(startTime));
            avgTemperature.setTime(currentTime);
            avgTemperature.setUnit(MetricUnit.C.name());
            avgTemperature.setValueNum(avgTemperature.translateUnit(Double.valueOf(avgValue), metricUnitMap.get(temperatureMetrics.getAvgTemperatureUnit()), MetricUnit.C));
            metricNameAndValueUnitMap.put(MetricName.SERVER_AVERAGE_TEMPERATURE, avgTemperature);
        }
        String peakValue = temperatureMetrics.getPeakTemperature();
        if (!NULLVALUE.equals(peakValue)) {
            ValueUnit peakTemperature = new ValueUnit();
            peakTemperature.setKey(MetricName.SERVER_PEAK_TEMPERATURE);
            long peakTime = WormholeDateFormat.cimDateToMilliseconds(temperatureMetrics.getPeakTemperatureTimeStamp());
            String startAndPeakTime = String.valueOf(startTime) + FlowgateConstant.SEPARATOR + String.valueOf(peakTime);
            peakTemperature.setExtraidentifier(startAndPeakTime);
            peakTemperature.setTime(currentTime);
            peakTemperature.setUnit(MetricUnit.C.name());
            peakTemperature.setValueNum(peakTemperature.translateUnit(Double.valueOf(peakValue), metricUnitMap.get(temperatureMetrics.getPeakTemperatureUnit()), MetricUnit.C));
            metricNameAndValueUnitMap.put(MetricName.SERVER_PEAK_TEMPERATURE, peakTemperature);
        }
    }
    // get metrics form power Manage plugin
    if (powerManage != null && powerManagerEnable) {
        String pluginId = powerManage.getId();
        PowerManageMetricsRequestBody body = new PowerManageMetricsRequestBody();
        body.setPluginId(pluginId);
        body.setEntityType(EntityType.Device.getValue());
        body.setEntityId(Integer.valueOf(deviceId));
        List<Integer> metricTypes = new ArrayList<Integer>();
        metricTypes.add(MetricType.INSTANT_POWER.getValue());
        // Inlet temperature
        metricTypes.add(MetricType.INSTANT_TEMP.getValue());
        body.setMetricTypes(metricTypes);
        body.setDuration(Duration.Recent.getValue());
        body.setSortOrder(SortOrder.Ascending.getValue());
        DeviceMetricsResult metrics = null;
        try {
            metrics = client.getMetricsFromPowerManage(body);
        } catch (HttpClientErrorException e) {
            logger.error("Not found any metrics data.", e);
            return metricNameAndValueUnitMap;
        }
        List<DeviceMetric> metricValues = metrics.getValue();
        if (metricValues.isEmpty()) {
            return metricNameAndValueUnitMap;
        }
        Map<Integer, String> metricTypeMap = new HashMap<Integer, String>();
        metricTypeMap.put(MetricType.INSTANT_POWER.getValue(), MetricName.SERVER_TOTAL_POWER);
        metricTypeMap.put(MetricType.INSTANT_TEMP.getValue(), MetricName.SERVER_FRONT_TEMPERATURE);
        CommonResult<PowerSetting> powerSettings = client.getCommonResult(PowerSetting.class);
        Map<Integer, Integer> powerSettingTypeAndValueMap = new HashMap<Integer, Integer>();
        for (PowerSetting powerSetting : powerSettings.getValue()) {
            powerSettingTypeAndValueMap.put(powerSetting.getId(), powerSetting.getValue());
        }
        for (DeviceMetric metric : metricValues) {
            if (MetricType.INSTANT_POWER.getValue() == metric.getType()) {
                ValueUnit instantPower = new ValueUnit();
                instantPower.setKey(MetricName.SERVER_POWER);
                instantPower.setTime(currentTime);
                instantPower.setUnit(MetricUnit.kW.name());
                int unitValue = powerSettingTypeAndValueMap.get(PowerSettingType.PowerUnit.getValue());
                // PowerUnit1 : watt
                // PowerUnit2 : BtuPerHr
                MetricUnit powerSourceUnit = metricUnitMap.get(PowerSettingType.PowerUnit.name() + unitValue);
                instantPower.setValueNum(instantPower.translateUnit(metric.getValue(), powerSourceUnit, MetricUnit.kW));
                metricNameAndValueUnitMap.put(MetricName.SERVER_POWER, instantPower);
            } else if (MetricType.INSTANT_TEMP.getValue() == metric.getType()) {
                ValueUnit inletTemperature = new ValueUnit();
                inletTemperature.setKey(MetricName.SERVER_FRONT_TEMPERATURE);
                inletTemperature.setTime(currentTime);
                inletTemperature.setUnit(MetricUnit.C.name());
                int unitValue = powerSettingTypeAndValueMap.get(PowerSettingType.TemperatureUnit.getValue());
                MetricUnit temperatureSourceUnit = metricUnitMap.get(PowerSettingType.TemperatureUnit.name() + unitValue);
                inletTemperature.setValueNum(inletTemperature.translateUnit(metric.getValue(), temperatureSourceUnit, MetricUnit.C));
                metricNameAndValueUnitMap.put(MetricName.SERVER_FRONT_TEMPERATURE, inletTemperature);
            }
        }
    }
    return metricNameAndValueUnitMap;
}
Also used : DeviceTemperature(com.vmware.flowgate.openmanage.datamodel.DeviceTemperature) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) PowerSetting(com.vmware.flowgate.openmanage.datamodel.PowerSetting) PowerManageMetricsRequestBody(com.vmware.flowgate.openmanage.datamodel.PowerManageMetricsRequestBody) ArrayList(java.util.ArrayList) DeviceMetric(com.vmware.flowgate.openmanage.datamodel.DeviceMetric) DeviceMetricsResult(com.vmware.flowgate.openmanage.datamodel.DeviceMetricsResult) DevicePower(com.vmware.flowgate.openmanage.datamodel.DevicePower) MetricUnit(com.vmware.flowgate.common.model.ValueUnit.MetricUnit) ValueUnit(com.vmware.flowgate.common.model.ValueUnit)

Example 2 with MetricUnit

use of com.vmware.flowgate.common.model.ValueUnit.MetricUnit 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;
}
Also used : ArrayList(java.util.ArrayList) MetricUnit(com.vmware.flowgate.common.model.ValueUnit.MetricUnit) WormholeException(com.vmware.flowgate.common.exception.WormholeException) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) PowerStripsRealtimeValue(com.vmware.flowgate.nlyteworker.model.PowerStripsRealtimeValue)

Example 3 with MetricUnit

use of com.vmware.flowgate.common.model.ValueUnit.MetricUnit in project flowgate by vmware.

the class PowerIQService method getSensorRealTimeData.

public List<RealTimeData> getSensorRealTimeData(FacilitySoftwareConfig powerIQ, List<Asset> assets) {
    HashMap<AdvanceSettingType, String> advanceSetting = getAdvanceSetting(powerIQ);
    List<RealTimeData> realtimeDatas = new ArrayList<RealTimeData>();
    String dateFormat = advanceSetting.get(AdvanceSettingType.DateFormat);
    String timezone = advanceSetting.get(AdvanceSettingType.TimeZone);
    String temperature = advanceSetting.get(AdvanceSettingType.TEMPERATURE_UNIT);
    String humidity = advanceSetting.get(AdvanceSettingType.HUMIDITY_UNIT);
    PowerIQAPIClient powerIQAPIClient = createClient(powerIQ);
    for (Asset asset : assets) {
        HashMap<String, String> sensorExtraInfo = asset.getJustificationfields();
        String sensorInfo = sensorExtraInfo.get(FlowgateConstant.SENSOR);
        Map<String, String> sensorInfoMap = null;
        try {
            sensorInfoMap = getInfoMap(sensorInfo);
        } catch (IOException e2) {
            continue;
        }
        String sensorId = sensorInfoMap.get(FlowgateConstant.SENSOR_ID_FROM_POWERIQ);
        Sensor sensor = null;
        try {
            sensor = powerIQAPIClient.getSensorById(sensorId);
        } catch (HttpClientErrorException e) {
            logger.error("Failed to query data from PowerIQ", e);
            IntegrationStatus integrationStatus = powerIQ.getIntegrationStatus();
            if (integrationStatus == null) {
                integrationStatus = new IntegrationStatus();
            }
            integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
            integrationStatus.setDetail(e.getMessage());
            integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
            updateIntegrationStatus(powerIQ);
            break;
        } catch (ResourceAccessException e1) {
            if (e1.getCause().getCause() instanceof ConnectException) {
                checkAndUpdateIntegrationStatus(powerIQ, e1.getMessage());
                break;
            }
            break;
        }
        SensorReading reading = sensor.getReading();
        if (reading == null || reading.getId() == 0) {
            continue;
        }
        RealTimeData realTimeData = new RealTimeData();
        String valueDateTime = reading.getReadingTime();
        long recordedTime = WormholeDateFormat.getLongTime(valueDateTime, dateFormat, timezone);
        if (recordedTime == -1) {
            logger.error("Failed to translate the time string: " + valueDateTime + ".And the dateformat is " + dateFormat);
            continue;
        }
        List<ValueUnit> values = new ArrayList<ValueUnit>();
        ValueUnit value = new ValueUnit();
        value.setTime(recordedTime);
        value.setKey(sensorAndMetricMap.get(sensor.getType()));
        String unit = reading.getUom();
        MetricUnit sourceUnit = null, targetUnit = null;
        switch(sensorAndMetricMap.get(sensor.getType())) {
            case MetricName.HUMIDITY:
                if (unit != null && !unit.isEmpty()) {
                    if (unit.equals("%")) {
                        sourceUnit = MetricUnit.percent;
                    } else {
                        sourceUnit = MetricUnit.valueOf(unit);
                    }
                } else {
                    if (humidity.equals("%")) {
                        sourceUnit = MetricUnit.percent;
                    } else {
                        sourceUnit = MetricUnit.valueOf(humidity);
                    }
                }
                targetUnit = MetricUnit.percent;
                break;
            case MetricName.TEMPERATURE:
                if (unit != null && !unit.isEmpty()) {
                    sourceUnit = MetricUnit.valueOf(unit.toUpperCase());
                } else {
                    sourceUnit = MetricUnit.valueOf(temperature.toUpperCase());
                }
                targetUnit = MetricUnit.C;
                break;
            default:
                break;
        }
        Double metricsValue = reading.getValue();
        if (metricsValue == null) {
            continue;
        }
        try {
            value.setValueNum(value.translateUnit(metricsValue, sourceUnit, targetUnit));
        } catch (WormholeException e) {
            logger.error("Cannot translate Unit", e);
        }
        if (targetUnit.toString().equals(MetricUnit.percent.toString())) {
            value.setUnit("%");
        } else {
            value.setUnit(targetUnit.toString());
        }
        values.add(value);
        realTimeData.setAssetID(asset.getId());
        realTimeData.setTime(recordedTime);
        realTimeData.setValues(values);
        realTimeData.setId(asset.getId() + "_" + recordedTime);
        realtimeDatas.add(realTimeData);
    }
    return realtimeDatas;
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ArrayList(java.util.ArrayList) WormholeException(com.vmware.flowgate.common.exception.WormholeException) IOException(java.io.IOException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) SensorReading(com.vmware.flowgate.poweriqworker.model.SensorReading) PowerIQAPIClient(com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient) Asset(com.vmware.flowgate.common.model.Asset) MetricUnit(com.vmware.flowgate.common.model.ValueUnit.MetricUnit) ValueUnit(com.vmware.flowgate.common.model.ValueUnit) AdvanceSettingType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType) Sensor(com.vmware.flowgate.poweriqworker.model.Sensor) ConnectException(java.net.ConnectException)

Aggregations

ValueUnit (com.vmware.flowgate.common.model.ValueUnit)3 MetricUnit (com.vmware.flowgate.common.model.ValueUnit.MetricUnit)3 ArrayList (java.util.ArrayList)3 WormholeException (com.vmware.flowgate.common.exception.WormholeException)2 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)2 Asset (com.vmware.flowgate.common.model.Asset)1 AdvanceSettingType (com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)1 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)1 PowerStripsRealtimeValue (com.vmware.flowgate.nlyteworker.model.PowerStripsRealtimeValue)1 DeviceMetric (com.vmware.flowgate.openmanage.datamodel.DeviceMetric)1 DeviceMetricsResult (com.vmware.flowgate.openmanage.datamodel.DeviceMetricsResult)1 DevicePower (com.vmware.flowgate.openmanage.datamodel.DevicePower)1 DeviceTemperature (com.vmware.flowgate.openmanage.datamodel.DeviceTemperature)1 PowerManageMetricsRequestBody (com.vmware.flowgate.openmanage.datamodel.PowerManageMetricsRequestBody)1 PowerSetting (com.vmware.flowgate.openmanage.datamodel.PowerSetting)1 PowerIQAPIClient (com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient)1 Sensor (com.vmware.flowgate.poweriqworker.model.Sensor)1 SensorReading (com.vmware.flowgate.poweriqworker.model.SensorReading)1 IOException (java.io.IOException)1