use of org.apache.apex.examples.machinedata.data.MachineKey in project apex-malhar by apache.
the class MachineInfoAveragingOperator method getKeyInfo.
/**
* This method returns the String for a given MachineKey instance
*
* @param key MachineKey instance that needs to be converted to string
* @return
*/
private String getKeyInfo(MachineKey key) {
StringBuilder sb = new StringBuilder();
if (key instanceof MachineKey) {
MachineKey mkey = (MachineKey) key;
Integer customer = mkey.getCustomer();
if (customer != null) {
sb.append("customer: " + customer + "\n");
}
Integer product = mkey.getProduct();
if (product != null) {
sb.append("product version: " + product + "\n");
}
Integer os = mkey.getOs();
if (os != null) {
sb.append("os version: " + os + "\n");
}
Integer software1 = mkey.getSoftware1();
if (software1 != null) {
sb.append("software1 version: " + software1 + "\n");
}
Integer software2 = mkey.getSoftware2();
if (software2 != null) {
sb.append("software2 version: " + software2 + "\n");
}
Integer software3 = mkey.getSoftware3();
if (software3 != null) {
sb.append("software3 version: " + software3 + "\n");
}
}
return sb.toString();
}
use of org.apache.apex.examples.machinedata.data.MachineKey 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.MachineKey in project apex-malhar by apache.
the class MachineInfoAveragingOperator method addTuple.
/**
* This adds the given tuple to the dataMap
*
* @param tuple input tuple
*/
private void addTuple(KeyHashValPair<MachineKey, AverageData> tuple) {
MachineKey key = tuple.getKey();
dataMap.put(key, tuple.getValue());
}
use of org.apache.apex.examples.machinedata.data.MachineKey in project apex-malhar by apache.
the class MachineInfoAveragingOperator method setGenAlert.
/**
* This method is used to artificially generate alerts
*
* @param genAlert
*/
public void setGenAlert(boolean genAlert) {
Calendar calendar = Calendar.getInstance();
long timestamp = System.currentTimeMillis();
calendar.setTimeInMillis(timestamp);
DateFormat minuteDateFormat = new SimpleDateFormat("HHmm");
Date date = calendar.getTime();
String timeKey = minuteDateFormat.format(date);
DateFormat dayDateFormat = new SimpleDateFormat("dd");
String day = dayDateFormat.format(date);
MachineKey alertKey = new MachineKey(timeKey, day);
alertKey.setCustomer(1);
alertKey.setProduct(5);
alertKey.setOs(10);
alertKey.setSoftware1(12);
alertKey.setSoftware2(14);
alertKey.setSoftware3(6);
MachineInfo machineInfo = new MachineInfo();
machineInfo.setMachineKey(alertKey);
machineInfo.setCpu(threshold + 1);
machineInfo.setRam(threshold + 1);
machineInfo.setHdd(threshold + 1);
smtpAlert.emit("CPU Alert: CPU Usage threshold (" + threshold + ") breached: current % usage: " + getKeyInfo(alertKey));
smtpAlert.emit("RAM Alert: RAM Usage threshold (" + threshold + ") breached: current % usage: " + getKeyInfo(alertKey));
smtpAlert.emit("HDD Alert: HDD Usage threshold (" + threshold + ") breached: current % usage: " + getKeyInfo(alertKey));
}
use of org.apache.apex.examples.machinedata.data.MachineKey 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