Search in sources :

Example 16 with Row

use of org.opennms.newts.api.Results.Row in project newts by OpenNMS.

the class RateTest method ratesWithDecimals.

/**
     * Verifies that counters (unsigned long) values return doubles with proper decimals
     * when converted to rates.
     */
@Test
public void ratesWithDecimals() {
    Iterator<Row<Sample>> samples = new SampleRowsBuilder(new Resource("localhost"), MetricType.COUNTER).row(1414598400).element("m1", 9223372034564703200.00).row(1414602000).element("m1", 9223372034601613300.00).row(1414605600).element("m1", 9223372034604530700.00).row(1414609200).element("m1", 9223372034608910300.00).row(1414612800).element("m1", 9223372034636612600.00).row(1414616400).element("m1", 9223372034639099900.00).row(1414620000).element("m1", 9223372034641185800.00).row(1414623600).element("m1", 9223372034642181100.00).build();
    Iterator<Results.Row<Sample>> output = new Rate(samples, Sets.newHashSet("m1")).iterator();
    double[] expectedRates = new double[] { Double.NaN, 10252.800000, 810.382222, 1216.568889, 7695.075556, 690.915556, 579.413333, 276.480000 };
    for (int i = 0; i < expectedRates.length; i++) {
        double actualRate = output.next().getElement("m1").getValue().doubleValue();
        assertEquals(expectedRates[i], actualRate, 0.0001);
    }
}
Also used : Rate(org.opennms.newts.aggregate.Rate) Resource(org.opennms.newts.api.Resource) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 17 with Row

use of org.opennms.newts.api.Results.Row in project newts by OpenNMS.

the class ResultProcessorTest method test.

@Test
public void test() {
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(900000000).element("m0", // Thu Jul  9 11:00:00 CDT 1998
    1).row(900000300).element("m0", 1).row(900000600).element("m0", 1).row(900000900).element("m0", 1).row(900001200).element("m0", 1).row(900001500).element("m0", 1).row(900001800).element("m0", 1).row(900002100).element("m0", 3).row(900002400).element("m0", 3).row(900002700).element("m0", 3).row(900003000).element("m0", 3).row(900003300).element("m0", 3).row(900003600).element("m0", 3).row(900003900).element("m0", 1).row(900004200).element("m0", 1).row(900004500).element("m0", 1).row(900004800).element("m0", 1).row(900005100).element("m0", 1).row(900005400).element("m0", 1).row(900005700).element("m0", 3).row(900006000).element("m0", 3).row(900006300).element("m0", 3).row(900006600).element("m0", 3).row(900006900).element("m0", 3).row(900007200).element("m0", // Thu Jul  9 13:00:00 CDT 1998
    3).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0-avg", "m0", Duration.seconds(600), AVERAGE).export("m0-avg");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900003600).element("m0-avg", 2.0).row(900007200).element("m0-avg", 2.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 18 with Row

use of org.opennms.newts.api.Results.Row 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 19 with Row

use of org.opennms.newts.api.Results.Row in project newts by OpenNMS.

the class Rate method next.

@Override
public Row<Sample> next() {
    if (!hasNext())
        throw new NoSuchElementException();
    Row<Sample> working = m_input.next();
    Row<Sample> result = new Row<>(working.getTimestamp(), working.getResource());
    for (String metricName : m_metrics) {
        Sample sample = working.getElement(metricName);
        if (sample == null) {
            continue;
        }
        // Use rate as result if one of counter types, else pass through as-is.
        result.addElement(COUNTERS.contains(sample.getType()) ? getRate(sample) : sample);
        m_prevSamples.put(sample.getName(), sample);
    }
    return result;
}
Also used : Sample(org.opennms.newts.api.Sample) Row(org.opennms.newts.api.Results.Row) NoSuchElementException(java.util.NoSuchElementException)

Example 20 with Row

use of org.opennms.newts.api.Results.Row in project newts by OpenNMS.

the class AggregationAttributesTest method test.

@Test
public void test() {
    Iterator<Row<Measurement>> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(1).element("m0", 1, mapFor("a", "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, mapFor("b", "1")).row(2100).element("m0", 3).row(2400).element("m0", 3, mapFor("a", "2")).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);
    Aggregation aggregation = new Aggregation(new Resource("localhost"), Timestamp.fromEpochSeconds(1), Timestamp.fromEpochSeconds(3300), rDescriptor, Duration.minutes(60), testData);
    Row<Measurement> row = aggregation.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(0)));
    assertThat(row.getElement("m0-avg").getAttributes(), nullValue());
    row = aggregation.next();
    assertThat(row.getTimestamp(), equalTo(fromEpochSeconds(3600)));
    assertAttributes(row.getElement("m0-avg"), mapFor("a", "2", "b", "1"));
}
Also used : Measurement(org.opennms.newts.api.Measurement) 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)

Aggregations

Row (org.opennms.newts.api.Results.Row)37 Resource (org.opennms.newts.api.Resource)33 Test (org.junit.Test)31 ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)30 MeasurementRowsBuilder (org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder)20 SampleRowsBuilder (org.opennms.newts.aggregate.Utils.SampleRowsBuilder)18 Measurement (org.opennms.newts.api.Measurement)14 Sample (org.opennms.newts.api.Sample)4 Timestamp (org.opennms.newts.api.Timestamp)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 Map (java.util.Map)2 Callable (java.util.concurrent.Callable)2 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)2 ResourceId (org.opennms.netmgt.model.ResourceId)2 Rate (org.opennms.newts.aggregate.Rate)2 Duration (org.opennms.newts.api.Duration)2