Search in sources :

Example 46 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class AggregationTest method test.

@Test
public void test() {
    Iterator<Row<Measurement>> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(1).element("m0", 1).row(300).element("m0", 1).row(600).element("m0", 1).row(900).element("m0", 1).row(1200).element("m0", 1).row(1500).element("m0", 1).row(1800).element("m0", 3).row(2100).element("m0", 3).row(2400).element("m0", 3).row(2700).element("m0", 3).row(3000).element("m0", 3).row(3300).element("m0", 3).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0-avg", "m0", Duration.seconds(600), AVERAGE).datasource("m0-min", "m0", Duration.seconds(600), MIN).datasource("m0-max", "m0", Duration.seconds(600), MAX);
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(0).element("m0-avg", NaN).element("m0-min", NaN).element("m0-max", NaN).row(3600).element("m0-avg", 2).element("m0-min", 1).element("m0-max", 3).build();
    Aggregation aggregation = new Aggregation(new Resource("localhost"), Timestamp.fromEpochSeconds(1), Timestamp.fromEpochSeconds(3300), rDescriptor, Duration.minutes(60), testData);
    assertRowsEqual(expected, aggregation);
}
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) Test(org.junit.Test)

Example 47 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class ComputeTest method testCalcOfCalc.

@Test
public void testCalcOfCalc() {
    Iterator<Row<Measurement>> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 20).element("out", 20).row(600).element("in", 60).element("out", 40).build();
    ResultDescriptor rDescriptor = new ResultDescriptor().datasource("in", AVERAGE).datasource("out", AVERAGE).calculate("sum", PLUS, "in", "out").calculate("tens", DIVIDE, "sum", "10").export("tens");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 20).element("out", 20).element("sum", 40).element("tens", 4).row(600).element("in", 60).element("out", 40).element("sum", 100).element("tens", 10).build();
    Compute compute = new Compute(rDescriptor, testData);
    assertRowsEqual(expected, compute);
}
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) Test(org.junit.Test)

Example 48 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class ComputeTest method testExpressions.

@Test
public void testExpressions() {
    Iterator<Row<Measurement>> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 20).element("out", 20).row(600).element("in", 60).element("out", 40).build();
    ResultDescriptor rDescriptor = new ResultDescriptor().datasource("in", "ifInOctets", seconds(600), AVERAGE).datasource("out", "ifOutOctets", seconds(600), AVERAGE).expression("sum", "in + out").expression("diff", "in - out").expression("ratio", "diff/sum").export("ratio");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 20).element("out", 20).element("sum", 40).element("diff", 0).element("ratio", 0).row(600).element("in", 60).element("out", 40).element("sum", 100).element("diff", 20).element("ratio", 0.2).build();
    Compute compute = new Compute(rDescriptor, testData);
    assertRowsEqual(expected, compute);
}
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) Test(org.junit.Test)

Example 49 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class ComputeTest method test.

@Test
public void test() {
    Iterator<Row<Measurement>> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 2).element("out", 2).row(600).element("in", 6).element("out", 4).build();
    ResultDescriptor rDescriptor = new ResultDescriptor().datasource("in", AVERAGE).datasource("out", AVERAGE).calculate("total", PLUS, "in", "out");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 2).element("out", 2).element("total", 4).row(600).element("in", 6).element("out", 4).element("total", 10).build();
    Compute compute = new Compute(rDescriptor, testData);
    assertRowsEqual(expected, compute);
}
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) Test(org.junit.Test)

Example 50 with Resource

use of org.opennms.newts.api.Resource 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)

Aggregations

Resource (org.opennms.newts.api.Resource)67 Test (org.junit.Test)50 Row (org.opennms.newts.api.Results.Row)35 ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)31 MeasurementRowsBuilder (org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder)20 SampleRowsBuilder (org.opennms.newts.aggregate.Utils.SampleRowsBuilder)20 Sample (org.opennms.newts.api.Sample)19 Measurement (org.opennms.newts.api.Measurement)14 Context (org.opennms.newts.api.Context)12 MetricRegistry (com.codahale.metrics.MetricRegistry)9 SearchResults (org.opennms.newts.api.search.SearchResults)8 Timestamp (org.opennms.newts.api.Timestamp)7 ResourcePath (org.opennms.netmgt.model.ResourcePath)6 ContextConfigurations (org.opennms.newts.cassandra.ContextConfigurations)6 Map (java.util.Map)5 Results (org.opennms.newts.api.Results)5 CassandraSession (org.opennms.newts.cassandra.CassandraSession)5 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 List (java.util.List)4 Result (org.opennms.newts.api.search.SearchResults.Result)4