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