Search in sources :

Example 21 with Timestamp

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

the class CassandraSampleRepository method select.

@Override
public Results<Sample> select(Context context, Resource resource, Optional<Timestamp> start, Optional<Timestamp> end) {
    Timer.Context timer = m_sampleSelectTimer.time();
    validateSelect(start, end);
    Timestamp upper = end.isPresent() ? end.get() : Timestamp.now();
    Timestamp lower = start.isPresent() ? start.get() : upper.minus(Duration.seconds(86400));
    LOG.debug("Querying database for resource {}, from {} to {}", resource, lower, upper);
    Results<Sample> samples = new Results<>();
    DriverAdapter driverAdapter = new DriverAdapter(cassandraSelect(context, resource, lower, upper));
    for (Row<Sample> row : driverAdapter) {
        samples.addRow(row);
    }
    LOG.debug("{} results returned from database", driverAdapter.getResultCount());
    m_samplesSelected.mark(driverAdapter.getResultCount());
    try {
        return samples;
    } finally {
        timer.stop();
    }
}
Also used : Timer(com.codahale.metrics.Timer) Results(org.opennms.newts.api.Results) Sample(org.opennms.newts.api.Sample) Timestamp(org.opennms.newts.api.Timestamp)

Example 22 with Timestamp

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

the class RateTest method test.

@Test
public void test() {
    Results<Sample> input = new Results<>();
    int rows = 10, cols = 2, rate = 100;
    for (int i = 1; i <= rows; i++) {
        Timestamp t = Timestamp.fromEpochMillis(i * 1000);
        for (int j = 0; j < cols; j++) {
            input.addElement(new Sample(t, m_resource, m_metrics[j], COUNTER, new Counter((i + j) * rate)));
        }
    }
    Iterator<Results.Row<Sample>> output = new Rate(input.iterator(), getMetrics(cols)).iterator();
    for (int i = 1; i <= rows; i++) {
        assertTrue("Insufficient number of results", output.hasNext());
        Results.Row<Sample> row = output.next();
        assertEquals("Unexpected row timestamp", Timestamp.fromEpochMillis(i * 1000), row.getTimestamp());
        assertEquals("Unexpected row resource", m_resource, row.getResource());
        assertEquals("Unexpected number of columns", cols, row.getElements().size());
        for (int j = 0; j < cols; j++) {
            String name = m_metrics[j];
            assertNotNull("Missing sample" + name, row.getElement(name));
            assertEquals("Unexpected sample name", name, row.getElement(name).getName());
            assertEquals("Unexpected sample type", GAUGE, row.getElement(name).getType());
            // Samples in the first row are null, this is normal.
            if (i != 1) {
                assertEquals("Incorrect rate value", 100.0d, row.getElement(name).getValue().doubleValue(), 0.0d);
            }
        }
    }
}
Also used : Counter(org.opennms.newts.api.Counter) Results(org.opennms.newts.api.Results) Sample(org.opennms.newts.api.Sample) Rate(org.opennms.newts.aggregate.Rate) Row(org.opennms.newts.api.Results.Row) Timestamp(org.opennms.newts.api.Timestamp) Test(org.junit.Test)

Example 23 with Timestamp

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

the class Aggregation method inRange.

// true if the working input Row is within the Range of the next output Row; false otherwise
private boolean inRange() {
    if (m_working == null || m_nextOut == null) {
        return false;
    }
    Timestamp rangeUpper = m_nextOut.getTimestamp();
    Timestamp rangeLower = m_nextOut.getTimestamp().minus(m_resolution);
    return m_working.getTimestamp().lte(rangeUpper) && m_working.getTimestamp().gt(rangeLower);
}
Also used : Timestamp(org.opennms.newts.api.Timestamp)

Example 24 with Timestamp

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

the class NewtsConverterTest method canConvertCounterToSample.

public void canConvertCounterToSample() {
    Resource resource = new Resource("resource", Optional.absent());
    DS ds = new DS();
    ds.setType(DSType.COUNTER);
    Timestamp timestamp = Timestamp.fromEpochSeconds(0);
    NewtsConverter.toSample(ds, resource, timestamp, UnsignedLong.MAX_VALUE.doubleValue());
}
Also used : Resource(org.opennms.newts.api.Resource) Timestamp(org.opennms.newts.api.Timestamp) DS(org.opennms.netmgt.rrd.model.v3.DS)

Aggregations

Timestamp (org.opennms.newts.api.Timestamp)24 Sample (org.opennms.newts.api.Sample)12 Duration (org.opennms.newts.api.Duration)8 Resource (org.opennms.newts.api.Resource)8 Test (org.junit.Test)7 Row (org.opennms.newts.api.Results.Row)5 Timer (com.codahale.metrics.Timer)4 Results (org.opennms.newts.api.Results)4 Map (java.util.Map)3 Future (java.util.concurrent.Future)3 IntervalGenerator (org.opennms.newts.aggregate.IntervalGenerator)3 Context (org.opennms.newts.api.Context)3 Gauge (org.opennms.newts.api.Gauge)3 Measurement (org.opennms.newts.api.Measurement)3 Timed (com.codahale.metrics.annotation.Timed)2 BoundStatement (com.datastax.driver.core.BoundStatement)2 List (java.util.List)2 SortedMap (java.util.SortedMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ResourcePath (org.opennms.netmgt.model.ResourcePath)2