Search in sources :

Example 1 with MachineKey

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();
}
Also used : MachineKey(org.apache.apex.examples.machinedata.data.MachineKey)

Example 2 with MachineKey

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();
}
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 3 with MachineKey

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());
}
Also used : MachineKey(org.apache.apex.examples.machinedata.data.MachineKey)

Example 4 with MachineKey

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));
}
Also used : MachineInfo(org.apache.apex.examples.machinedata.data.MachineInfo) MachineKey(org.apache.apex.examples.machinedata.data.MachineKey) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 5 with MachineKey

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());
    }
}
Also used : MachineKey(org.apache.apex.examples.machinedata.data.MachineKey) AverageData(org.apache.apex.examples.machinedata.data.AverageData)

Aggregations

MachineKey (org.apache.apex.examples.machinedata.data.MachineKey)13 MachineInfo (org.apache.apex.examples.machinedata.data.MachineInfo)6 Calendar (java.util.Calendar)5 Date (java.util.Date)5 Map (java.util.Map)5 ResourceType (org.apache.apex.examples.machinedata.data.ResourceType)4 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)3 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)3 TimeBucketKey (org.apache.apex.malhar.lib.util.TimeBucketKey)3 AverageData (org.apache.apex.examples.machinedata.data.AverageData)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 MachineInfoAveragingOperator (org.apache.apex.examples.machinedata.operator.MachineInfoAveragingOperator)1 MachineInfoAveragingPrerequisitesOperator (org.apache.apex.examples.machinedata.operator.MachineInfoAveragingPrerequisitesOperator)1 SmtpOutputOperator (org.apache.apex.malhar.lib.io.SmtpOutputOperator)1