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