Search in sources :

Example 1 with AverageData

use of org.apache.apex.examples.machinedata.data.AverageData in project apex-malhar by apache.

the class MachineInfoAveragingOperator method endWindow.

@Override
public void endWindow() {
    for (Map.Entry<MachineKey, AverageData> entry : dataMap.entrySet()) {
        MachineKey key = entry.getKey();
        AverageData averageResultMap = entry.getValue();
        Map<String, String> averageResult = Maps.newHashMap();
        long count = averageResultMap.getCount();
        double average = averageResultMap.getCpu() / count;
        averageResult.put(CPU, average + "");
        emitAlert(average, CPU, key);
        average = averageResultMap.getHdd() / count;
        averageResult.put(HDD, average + "");
        emitAlert(average, HDD, key);
        average = averageResultMap.getRam() / count;
        averageResult.put(RAM, average + "");
        emitAlert(average, RAM, key);
        averageResult.put(DAY, key.getDay());
        outputPort.emit(new KeyValPair<>(key, averageResult));
    }
    dataMap.clear();
}
Also used : MachineKey(org.apache.apex.examples.machinedata.data.MachineKey) AverageData(org.apache.apex.examples.machinedata.data.AverageData) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AverageData

use of org.apache.apex.examples.machinedata.data.AverageData in project apex-malhar by apache.

the class MachineInfoAveragingUnifier method process.

@Override
public void process(KeyHashValPair<MachineKey, AverageData> arg0) {
    MachineKey tupleKey = arg0.getKey();
    AverageData averageData = sums.get(tupleKey);
    AverageData tupleValue = arg0.getValue();
    if (averageData == null) {
        sums.put(tupleKey, tupleValue);
    } else {
        averageData.setCpu(averageData.getCpu() + tupleValue.getCpu());
        averageData.setRam(averageData.getRam() + tupleValue.getRam());
        averageData.setHdd(averageData.getHdd() + tupleValue.getHdd());
        averageData.setCount(averageData.getCount() + tupleValue.getCount());
    }
}
Also used : MachineKey(org.apache.apex.examples.machinedata.data.MachineKey) AverageData(org.apache.apex.examples.machinedata.data.AverageData)

Aggregations

AverageData (org.apache.apex.examples.machinedata.data.AverageData)2 MachineKey (org.apache.apex.examples.machinedata.data.MachineKey)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1