Search in sources :

Example 6 with SampleRowsBuilder

use of org.opennms.newts.aggregate.Utils.SampleRowsBuilder in project newts by OpenNMS.

the class ResultProcessorTest method testCounterRate.

@Test
public void testCounterRate() {
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.COUNTER).row(900000000).element("m0", // Thu Jul  9 11:00:00 CDT 1998
    3000).row(900000300).element("m0", 6000).row(900000600).element("m0", 9000).row(900000900).element("m0", 12000).row(900001200).element("m0", 15000).row(900001500).element("m0", 18000).row(900001800).element("m0", 21000).row(900002100).element("m0", 24000).row(900002400).element("m0", 27000).row(900002700).element("m0", 30000).row(900003000).element("m0", 33000).row(900003300).element("m0", 36000).row(900003600).element("m0", 39000).row(900003900).element("m0", 42000).row(900004200).element("m0", 45000).row(900004500).element("m0", 48000).row(900004800).element("m0", 51000).row(900005100).element("m0", 54000).row(900005400).element("m0", 57000).row(900005700).element("m0", 60000).row(900006000).element("m0", 63000).row(900006300).element("m0", 66000).row(900006600).element("m0", 69000).row(900006900).element("m0", 72000).row(900007200).element("m0", // Thu Jul  9 13:00:00 CDT 1998
    75000).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0", AVERAGE).export("m0");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900003600).element("m0", 10.0).row(900007200).element("m0", 10.0).build();
    ResultProcessor processor = new ResultProcessor(new Resource("localhost"), Timestamp.fromEpochSeconds(900003600), Timestamp.fromEpochSeconds(900007200), rDescriptor, Duration.minutes(60));
    assertRowsEqual(expected, processor.process(testData).iterator());
}
Also used : MeasurementRowsBuilder(org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 7 with SampleRowsBuilder

use of org.opennms.newts.aggregate.Utils.SampleRowsBuilder in project newts by OpenNMS.

the class PrimaryDataAttributesTest method testOverlappingAttributes.

@Test
public void testOverlappingAttributes() {
    // This set has samples with attributes that fall strictly within sample intervals.
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(900000297).element("m0", 1, mapFor("a", "1")).row(900000298).element("m0", 1, mapFor("a", "2", "c", "5")).row(900000301).element("m0", 1, mapFor("a", "3")).row(900000597).element("m0", 1, mapFor("b", "1")).row(900000598).element("m0", 1, mapFor("b", "2")).row(900000599).element("m0", 1, mapFor("b", "3")).row(900000899).element("m0", 2).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(600), null);
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(900000300), Timestamp.fromEpochSeconds(900000900), rDescriptor, testData);
    // Row 1
    Row<Measurement> row = primaryData.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(900000300)));
    assertAttributes(row.getElement("m0"), mapFor("a", "3", "c", "5"));
    // Row 2
    row = primaryData.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(900000600)));
    assertAttributes(row.getElement("m0"), mapFor("a", "3", "b", "3"));
    // Row 3
    row = primaryData.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(900000900)));
    assertAttributes(row.getElement("m0"), mapFor());
}
Also used : Measurement(org.opennms.newts.api.Measurement) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 8 with SampleRowsBuilder

use of org.opennms.newts.aggregate.Utils.SampleRowsBuilder in project newts by OpenNMS.

the class PrimaryDataAttributesTest method testMultipleSamples.

@Test
public void testMultipleSamples() {
    // This set has samples with attributes that fall strictly within sample intervals.
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(900000297).element("m0", 1, mapFor("a", "1")).element("m1", 2, mapFor("aa", "11")).row(900000298).element("m0", 1, mapFor("a", "2", "c", "5")).row(900000301).element("m0", 1, mapFor("a", "3")).element("m1", 2, mapFor("aa", "33")).row(900000597).element("m0", 1, mapFor("b", "1")).element("m1", 2, mapFor("bb", "11")).row(900000598).element("m0", 1, mapFor("b", "2")).element("m1", 2, mapFor("bb", "22")).row(900000599).element("m0", 1, mapFor("b", "3")).element("m1", 2, mapFor("bb", "33")).row(900000899).element("m0", 2).element("m1", 3).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(600), null).datasource("m1", "m1", Duration.seconds(600), null);
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(900000300), Timestamp.fromEpochSeconds(900000900), rDescriptor, testData);
    // Row 1
    Row<Measurement> row = primaryData.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(900000300)));
    assertAttributes(row.getElement("m0"), mapFor("a", "3", "c", "5"));
    assertAttributes(row.getElement("m1"), mapFor("aa", "33"));
    // Row 2
    row = primaryData.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(900000600)));
    assertAttributes(row.getElement("m0"), mapFor("a", "3", "b", "3"));
    assertAttributes(row.getElement("m1"), mapFor("aa", "33", "bb", "33"));
    // Row 3
    row = primaryData.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(900000900)));
    assertAttributes(row.getElement("m0"), mapFor());
    assertAttributes(row.getElement("m1"), mapFor());
}
Also used : Measurement(org.opennms.newts.api.Measurement) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 9 with SampleRowsBuilder

use of org.opennms.newts.aggregate.Utils.SampleRowsBuilder in project newts by OpenNMS.

the class PrimaryDataAttributesTest method testAttributesWithinInterval.

@Test
public void testAttributesWithinInterval() {
    // This set has samples with attributes that fall strictly within sample intervals.
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(900000297).element("m0", 1, mapFor("a", "1")).row(900000298).element("m0", 1, mapFor("a", "2", "c", "5")).row(900000299).element("m0", 1, mapFor("a", "3")).row(900000305).element("m0", 1).row(900000597).element("m0", 1, mapFor("b", "1")).row(900000598).element("m0", 1, mapFor("b", "2")).row(900000599).element("m0", 1, mapFor("b", "3")).row(900000899).element("m0", 2).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(600), null);
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(900000300), Timestamp.fromEpochSeconds(900000900), rDescriptor, testData);
    // Row 1
    Row<Measurement> row = primaryData.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(900000300)));
    assertAttributes(row.getElement("m0"), mapFor("a", "3", "c", "5"));
    // Row 2
    row = primaryData.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(900000600)));
    assertAttributes(row.getElement("m0"), mapFor("b", "3"));
    // Row 3
    row = primaryData.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(900000900)));
    assertAttributes(row.getElement("m0"), mapFor());
}
Also used : Measurement(org.opennms.newts.api.Measurement) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 10 with SampleRowsBuilder

use of org.opennms.newts.aggregate.Utils.SampleRowsBuilder in project newts by OpenNMS.

the class PrimaryDataTest method testShortSamples.

@Test
public void testShortSamples() {
    // Samples occur prior to the nearest step interval boundary.
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(000).element("m0", 0).element("m1", 1).row(250).element("m0", 1).element("m1", 2).row(550).element("m0", 2).element("m1", 3).row(850).element("m0", 3).element("m1", 4).build();
    // Minimal result descriptor
    ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(600), null).datasource("m1", "m1", Duration.seconds(600), null);
    // Expected results
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("m0", 1.16666667).element("m1", 2.16666667).row(600).element("m0", 2.16666667).element("m1", 3.16666667).row(900).element("m0", 3.0).element("m1", 4.0).build();
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(300), Timestamp.fromEpochSeconds(900), rDescriptor, testData);
    assertRowsEqual(expected, primaryData);
}
Also used : MeasurementRowsBuilder(org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 SampleRowsBuilder (org.opennms.newts.aggregate.Utils.SampleRowsBuilder)18 Resource (org.opennms.newts.api.Resource)18 Row (org.opennms.newts.api.Results.Row)18 ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)17 MeasurementRowsBuilder (org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder)14 Measurement (org.opennms.newts.api.Measurement)3 Rate (org.opennms.newts.aggregate.Rate)1 BinaryFunction (org.opennms.newts.api.query.ResultDescriptor.BinaryFunction)1