Search in sources :

Example 11 with Measurement

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

the class Compute method next.

@Override
public Row<Measurement> next() {
    if (!hasNext())
        throw new NoSuchElementException();
    Row<Measurement> row = m_input.next();
    for (Calculation calc : m_resultDescriptor.getCalculations().values()) {
        double v = calc.getCalculationFunction().apply(getValues(row, calc.getArgs()));
        row.addElement(new Measurement(row.getTimestamp(), row.getResource(), calc.getLabel(), v));
    }
    return row;
}
Also used : Measurement(org.opennms.newts.api.Measurement) Calculation(org.opennms.newts.api.query.Calculation) NoSuchElementException(java.util.NoSuchElementException)

Example 12 with Measurement

use of org.opennms.newts.api.Measurement 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 13 with Measurement

use of org.opennms.newts.api.Measurement 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 14 with Measurement

use of org.opennms.newts.api.Measurement 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 15 with Measurement

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

the class Utils method assertRowsEqual.

/**
 * Assert that two sets of {@link Row} results are equal.
 *
 * @param expectedRows
 *            expected value
 * @param actualRows
 *            actual value
 */
static void assertRowsEqual(Iterator<Row<Measurement>> expectedRows, Iterator<Row<Measurement>> actualRows) {
    while (actualRows.hasNext()) {
        Row<Measurement> actual = actualRows.next();
        assertTrue("Extraneous result row(s)", expectedRows.hasNext());
        Row<Measurement> expected = expectedRows.next();
        assertEquals("Unexpected row resource", expected.getResource(), actual.getResource());
        assertEquals("Unexpected row timestamp", expected.getTimestamp(), actual.getTimestamp());
        assertEquals("Measurement count mismatch", expected.getElements().size(), actual.getElements().size());
        for (Measurement m : actual.getElements()) {
            assertNotNull("Extraneous result measurement(s)", expected.getElement(m.getName()));
            assertSamplesEqual(expected.getElement(m.getName()), m);
        }
    }
    assertFalse("Missing result rows(s)", expectedRows.hasNext());
}
Also used : Measurement(org.opennms.newts.api.Measurement)

Aggregations

Measurement (org.opennms.newts.api.Measurement)21 Resource (org.opennms.newts.api.Resource)14 Row (org.opennms.newts.api.Results.Row)14 ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)12 Test (org.junit.Test)10 Results (org.opennms.newts.api.Results)4 MeasurementRowsBuilder (org.opennms.newts.persistence.cassandra.Utils.MeasurementRowsBuilder)4 SampleRowsBuilder (org.opennms.newts.persistence.cassandra.Utils.SampleRowsBuilder)4 NoSuchElementException (java.util.NoSuchElementException)3 Source (org.opennms.netmgt.measurements.model.Source)3 OnmsResource (org.opennms.netmgt.model.OnmsResource)3 SampleRowsBuilder (org.opennms.newts.aggregate.Utils.SampleRowsBuilder)3 Duration (org.opennms.newts.api.Duration)3 Timestamp (org.opennms.newts.api.Timestamp)3 Map (java.util.Map)2 Callable (java.util.concurrent.Callable)2 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)2 AggregationFunction (org.opennms.newts.api.query.AggregationFunction)2 Datasource (org.opennms.newts.api.query.Datasource)2 Meter (com.codahale.metrics.Meter)1