Search in sources :

Example 21 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class ProfileWriter method main.

public static void main(String[] args) throws Exception {
    RowKeyBuilder rowKeyBuilder = new SaltyRowKeyBuilder();
    ColumnBuilder columnBuilder = new ValueOnlyColumnBuilder();
    Configuration config = HBaseConfiguration.create();
    config.set("hbase.master.hostname", "node1");
    config.set("hbase.regionserver.hostname", "node1");
    config.set("hbase.zookeeper.quorum", "node1");
    HTableProvider provider = new HTableProvider();
    HTableInterface table = provider.getTable(config, "profiler");
    long when = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(2);
    ProfileMeasurement measure = new ProfileMeasurement().withProfileName("profile1").withEntity("192.168.66.121").withPeriod(when, 15, TimeUnit.MINUTES);
    ProfileWriter writer = new ProfileWriter(rowKeyBuilder, columnBuilder, table);
    writer.write(measure, 2 * 24 * 4, Collections.emptyList(), val -> new Random().nextInt(10));
}
Also used : SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) HTableProvider(org.apache.metron.hbase.HTableProvider) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Random(java.util.Random) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) SaltyRowKeyBuilder(org.apache.metron.profiler.hbase.SaltyRowKeyBuilder) RowKeyBuilder(org.apache.metron.profiler.hbase.RowKeyBuilder) ColumnBuilder(org.apache.metron.profiler.hbase.ColumnBuilder) ValueOnlyColumnBuilder(org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface)

Example 22 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class GetProfileTest method testWithTwoGroups.

/**
 * Values should be retrievable that have been stored within a 'group'.
 */
@Test
public void testWithTwoGroups() {
    final int periodsPerHour = 4;
    final int expectedValue = 2302;
    final int hours = 2;
    final long startTime = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(hours);
    final List<Object> group = Arrays.asList("weekdays", "tuesday");
    // setup - write some measurements to be read later
    final int count = hours * periodsPerHour;
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile1").withEntity("entity1").withPeriod(startTime, periodDuration, periodUnits);
    profileWriter.write(m, count, group, val -> expectedValue);
    // create a variable that contains the groups to use
    state.put("groups", group);
    // execute - read the profile values
    String expr = "PROFILE_GET('profile1', 'entity1', PROFILE_FIXED(4, 'HOURS'), ['weekdays', 'tuesday'])";
    @SuppressWarnings("unchecked") List<Integer> result = run(expr, List.class);
    // validate - expect to read all values from the past 4 hours
    Assert.assertEquals(count, result.size());
    // test the deprecated but allowed "varargs" form of groups specification
    expr = "PROFILE_GET('profile1', 'entity1', PROFILE_FIXED(4, 'HOURS'), 'weekdays', 'tuesday')";
    result = run(expr, List.class);
    // validate - expect to read all values from the past 4 hours
    Assert.assertEquals(count, result.size());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Example 23 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class GetProfileTest method testOutsideTimeHorizon.

/**
 * If the time horizon specified does not include any profile measurements, then
 * none should be returned.
 */
@Test
public void testOutsideTimeHorizon() {
    final int expectedValue = 2302;
    final int hours = 2;
    final long startTime = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(hours);
    final List<Object> group = Collections.emptyList();
    // setup - write a single value from 2 hours ago
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile1").withEntity("entity1").withPeriod(startTime, periodDuration, periodUnits);
    profileWriter.write(m, 1, group, val -> expectedValue);
    // create a variable that contains the groups to use
    state.put("groups", group);
    // execute - read the profile values
    String expr = "PROFILE_GET('profile1', 'entity1', PROFILE_FIXED(4, 'SECONDS'))";
    @SuppressWarnings("unchecked") List<Integer> result = run(expr, List.class);
    // validate - there should be no values from only 4 seconds ago
    Assert.assertEquals(0, result.size());
}
Also used : ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Example 24 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class GetProfileTest method testWithNoGroups.

/**
 * Values should be retrievable that have NOT been stored within a group.
 */
@Test
public void testWithNoGroups() {
    final int periodsPerHour = 4;
    final int expectedValue = 2302;
    final int hours = 2;
    final long startTime = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(hours);
    final List<Object> group = Collections.emptyList();
    // setup - write some measurements to be read later
    final int count = hours * periodsPerHour;
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile1").withEntity("entity1").withPeriod(startTime, periodDuration, periodUnits);
    profileWriter.write(m, count, group, val -> expectedValue);
    // execute - read the profile values - no groups
    String expr = "PROFILE_GET('profile1', 'entity1', PROFILE_FIXED(4, 'HOURS'))";
    @SuppressWarnings("unchecked") List<Integer> result = run(expr, List.class);
    // validate - expect to read all values from the past 4 hours
    Assert.assertEquals(count, result.size());
}
Also used : ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Example 25 with ProfileMeasurement

use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.

the class GetProfileTest method testWithOneGroup.

/**
 * Values should be retrievable that have been stored within a 'group'.
 */
@Test
public void testWithOneGroup() {
    final int periodsPerHour = 4;
    final int expectedValue = 2302;
    final int hours = 2;
    final long startTime = System.currentTimeMillis() - TimeUnit.HOURS.toMillis(hours);
    final List<Object> group = Arrays.asList("weekends");
    // setup - write some measurements to be read later
    final int count = hours * periodsPerHour;
    ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile1").withEntity("entity1").withPeriod(startTime, periodDuration, periodUnits);
    profileWriter.write(m, count, group, val -> expectedValue);
    // create a variable that contains the groups to use
    state.put("groups", group);
    // execute - read the profile values
    String expr = "PROFILE_GET('profile1', 'entity1', PROFILE_FIXED(4, 'HOURS'), ['weekends'])";
    @SuppressWarnings("unchecked") List<Integer> result = run(expr, List.class);
    // validate - expect to read all values from the past 4 hours
    Assert.assertEquals(count, result.size());
    // test the deprecated but allowed "varargs" form of groups specification
    expr = "PROFILE_GET('profile1', 'entity1', PROFILE_FIXED(4, 'HOURS'), 'weekends')";
    result = run(expr, List.class);
    // validate - expect to read all values from the past 4 hours
    Assert.assertEquals(count, result.size());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Test(org.junit.Test)

Aggregations

ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)27 Test (org.junit.Test)19 List (java.util.List)6 SaltyRowKeyBuilder (org.apache.metron.profiler.hbase.SaltyRowKeyBuilder)6 ArrayList (java.util.ArrayList)5 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)5 Tuple (org.apache.storm.tuple.Tuple)5 Values (org.apache.storm.tuple.Values)4 JSONObject (org.json.simple.JSONObject)4 Before (org.junit.Before)4 ColumnBuilder (org.apache.metron.profiler.hbase.ColumnBuilder)3 ValueOnlyColumnBuilder (org.apache.metron.profiler.hbase.ValueOnlyColumnBuilder)3 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 TimeUnit (java.util.concurrent.TimeUnit)2 ProfileConfig (org.apache.metron.common.configuration.profiler.ProfileConfig)2 MockHTable (org.apache.metron.hbase.mock.MockHTable)2 MessageDistributor (org.apache.metron.profiler.MessageDistributor)2