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