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();
}
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());
}
}
Aggregations