Search in sources :

Example 1 with MachineInfo

use of org.apache.apex.examples.machinedata.data.MachineInfo 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 2 with MachineInfo

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

the class InputReceiver method emitTuples.

@Override
public void emitTuples() {
    int count = 0;
    Calendar calendar = Calendar.getInstance();
    Date date = calendar.getTime();
    String timeKey = minuteDateFormat.format(date);
    String day = dayDateFormat.format(date);
    while (count < tupleBlastSize) {
        randomGen.setSeed(System.currentTimeMillis());
        int customerVal = genCustomerId();
        int productVal = genProductVer();
        int osVal = genOsVer();
        int software1Val = genSoftware1Ver();
        int software2Val = genSoftware2Ver();
        int software3Val = genSoftware3Ver();
        int deviceIdVal = genDeviceId();
        int cpuVal = genCpu(calendar);
        int ramVal = genRam(calendar);
        int hddVal = genHdd(calendar);
        MachineKey machineKey = new MachineKey(timeKey, day);
        machineKey.setCustomer(customerVal);
        machineKey.setProduct(productVal);
        machineKey.setOs(osVal);
        machineKey.setDeviceId(deviceIdVal);
        machineKey.setSoftware1(software1Val);
        machineKey.setSoftware2(software2Val);
        machineKey.setSoftware3(software3Val);
        MachineInfo machineInfo = new MachineInfo();
        machineInfo.setMachineKey(machineKey);
        machineInfo.setCpu(cpuVal);
        machineInfo.setRam(ramVal);
        machineInfo.setHdd(hddVal);
        outputInline.emit(machineInfo);
        count++;
    }
}
Also used : MachineInfo(org.apache.apex.examples.machinedata.data.MachineInfo) MachineKey(org.apache.apex.examples.machinedata.data.MachineKey) Calendar(java.util.Calendar) Date(java.util.Date)

Example 3 with MachineInfo

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

the class CalculatorOperatorTest method testStandarDeviation.

public void testStandarDeviation(CalculatorOperator oper) {
    CollectorTestSink sortSink = new CollectorTestSink();
    oper.sdOutputPort.setSink(sortSink);
    Calendar calendar = Calendar.getInstance();
    Date date = calendar.getTime();
    String timeKey = minuteDateFormat.format(date);
    String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
    Integer vs = new Integer(1);
    MachineKey mk = new MachineKey(timeKey, day, vs, vs, vs, vs, vs, vs, vs);
    oper.beginWindow(0);
    MachineInfo info = new MachineInfo(mk, 1, 1, 1);
    oper.dataPort.process(info);
    info.setCpu(2);
    oper.dataPort.process(info);
    info.setCpu(3);
    oper.dataPort.process(info);
    oper.endWindow();
    Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
    for (Object o : sortSink.collectedTuples) {
        LOG.debug(o.toString());
        KeyValPair<TimeBucketKey, Map<ResourceType, Double>> keyValPair = (KeyValPair<TimeBucketKey, Map<ResourceType, Double>>) o;
        Assert.assertEquals("emitted value for 'cpu' was ", getSD(ImmutableList.of(1, 2, 3)), keyValPair.getValue().get(ResourceType.CPU), 0);
        Assert.assertEquals("emitted value for 'hdd' was ", getSD(ImmutableList.of(1, 1, 1)), keyValPair.getValue().get(ResourceType.HDD), 0);
        Assert.assertEquals("emitted value for 'ram' was ", getSD(ImmutableList.of(1, 1, 1)), keyValPair.getValue().get(ResourceType.RAM), 0);
    }
    LOG.debug("Done sd testing\n");
}
Also used : Calendar(java.util.Calendar) ResourceType(org.apache.apex.examples.machinedata.data.ResourceType) Date(java.util.Date) TimeBucketKey(org.apache.apex.malhar.lib.util.TimeBucketKey) MachineInfo(org.apache.apex.examples.machinedata.data.MachineInfo) MachineKey(org.apache.apex.examples.machinedata.data.MachineKey) KeyValPair(org.apache.apex.malhar.lib.util.KeyValPair) Map(java.util.Map) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink)

Example 4 with MachineInfo

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

the class CalculatorOperatorTest method testPercentile.

public void testPercentile(CalculatorOperator oper) {
    CollectorTestSink sortSink = new CollectorTestSink();
    oper.percentileOutputPort.setSink(sortSink);
    oper.setKthPercentile(50);
    Calendar calendar = Calendar.getInstance();
    Date date = calendar.getTime();
    String timeKey = minuteDateFormat.format(date);
    String day = calendar.get(Calendar.DAY_OF_MONTH) + "";
    Integer vs = new Integer(1);
    MachineKey mk = new MachineKey(timeKey, day, vs, vs, vs, vs, vs, vs, vs);
    oper.beginWindow(0);
    MachineInfo info = new MachineInfo(mk, 1, 1, 1);
    oper.dataPort.process(info);
    info.setCpu(2);
    oper.dataPort.process(info);
    info.setCpu(3);
    oper.dataPort.process(info);
    oper.endWindow();
    Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size());
    for (Object o : sortSink.collectedTuples) {
        LOG.debug(o.toString());
        KeyValPair<TimeBucketKey, Map<ResourceType, Double>> keyValPair = (KeyValPair<TimeBucketKey, Map<ResourceType, Double>>) o;
        Assert.assertEquals("emitted value for 'cpu' was ", 2.0, keyValPair.getValue().get(ResourceType.CPU), 0);
        Assert.assertEquals("emitted value for 'hdd' was ", 1.0, keyValPair.getValue().get(ResourceType.HDD), 0);
        Assert.assertEquals("emitted value for 'ram' was ", 1.0, keyValPair.getValue().get(ResourceType.RAM), 0);
    }
    LOG.debug("Done percentile testing\n");
}
Also used : Calendar(java.util.Calendar) ResourceType(org.apache.apex.examples.machinedata.data.ResourceType) Date(java.util.Date) TimeBucketKey(org.apache.apex.malhar.lib.util.TimeBucketKey) MachineInfo(org.apache.apex.examples.machinedata.data.MachineInfo) MachineKey(org.apache.apex.examples.machinedata.data.MachineKey) KeyValPair(org.apache.apex.malhar.lib.util.KeyValPair) Map(java.util.Map) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink)

Example 5 with MachineInfo

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

the class DimensionGenerator method emitDimensions.

/**
 * This function takes in the tuple from upstream operator and generates tuples with different dimension combinations
 *
 * @param tuple
 */
private void emitDimensions(MachineInfo tuple) {
    MachineKey tupleKey = tuple.getMachineKey();
    for (int i = 0; i < 64; i++) {
        MachineKey machineKey = new MachineKey(tupleKey.getTimeKey(), tupleKey.getDay());
        if ((i & 1) != 0) {
            machineKey.setCustomer(tupleKey.getCustomer());
        }
        if ((i & 2) != 0) {
            machineKey.setProduct(tupleKey.getProduct());
        }
        if ((i & 4) != 0) {
            machineKey.setOs(tupleKey.getOs());
        }
        if ((i & 8) != 0) {
            machineKey.setDeviceId(tupleKey.getDeviceId());
        }
        if ((i & 16) != 0) {
            machineKey.setSoftware1(tupleKey.getSoftware1());
        }
        if ((i & 32) != 0) {
            machineKey.setSoftware2(tupleKey.getSoftware2());
        }
        int cpu = tuple.getCpu();
        int ram = tuple.getRam();
        int hdd = tuple.getHdd();
        MachineInfo machineInfo = new MachineInfo();
        machineInfo.setMachineKey(machineKey);
        machineInfo.setCpu((cpu < threshold) ? cpu : threshold);
        machineInfo.setRam((ram < threshold) ? ram : threshold);
        machineInfo.setHdd((hdd < threshold) ? hdd : threshold);
        outputInline.emit(machineInfo);
        output.emit(machineInfo);
    }
}
Also used : MachineInfo(org.apache.apex.examples.machinedata.data.MachineInfo) MachineKey(org.apache.apex.examples.machinedata.data.MachineKey)

Aggregations

MachineInfo (org.apache.apex.examples.machinedata.data.MachineInfo)6 MachineKey (org.apache.apex.examples.machinedata.data.MachineKey)6 Calendar (java.util.Calendar)5 Date (java.util.Date)5 Map (java.util.Map)3 ResourceType (org.apache.apex.examples.machinedata.data.ResourceType)3 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 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1