use of org.opennms.newts.api.query.ResultDescriptor in project opennms by OpenNMS.
the class NewtsFetchStrategy method getMeasurementsForResourceCallable.
private Callable<Collection<Row<Measurement>>> getMeasurementsForResourceCallable(final String newtsResourceId, final List<Source> listOfSources, final Optional<Timestamp> start, final Optional<Timestamp> end, final LateAggregationParams lag) {
return new Callable<Collection<Row<Measurement>>>() {
@Override
public Collection<Row<Measurement>> call() throws Exception {
ResultDescriptor resultDescriptor = new ResultDescriptor(lag.getInterval());
for (Source source : listOfSources) {
final String metricName = source.getAttribute();
final String name = source.getLabel();
final AggregationFunction fn = toAggregationFunction(source.getAggregation());
resultDescriptor.datasource(name, metricName, lag.getHeartbeat(), fn);
resultDescriptor.export(name);
}
LOG.debug("Querying Newts for resource id {} with result descriptor: {}", newtsResourceId, resultDescriptor);
Results<Measurement> results = m_sampleRepository.select(m_context, new Resource(newtsResourceId), start, end, resultDescriptor, Optional.of(Duration.millis(lag.getStep())), limitConcurrentAggregationsCallback);
Collection<Row<Measurement>> rows = results.getRows();
LOG.debug("Found {} rows.", rows.size());
return rows;
}
};
}
use of org.opennms.newts.api.query.ResultDescriptor in project opennms by OpenNMS.
the class NewtsConverterIT method execute.
private void execute(final boolean storeByGroup, final boolean storeByForeignSource, final boolean useRrdTool) throws Exception {
final Path data = OPENNMS_HOME.resolve("share").resolve(useRrdTool ? "rrd" : "jrb").resolve(storeByGroup ? "sbg" : "sbm").resolve(storeByForeignSource ? "fs" : "id");
assertTrue(Files.isDirectory(data));
exit.expectSystemExitWithStatus(0);
exit.checkAssertionAfterwards(() -> {
assertThat(resourceStorageDao.exists(RESOURCE_PATH_SNMP, 0), is(true));
assertThat(resourceStorageDao.getAttributes(RESOURCE_PATH_SNMP), hasItems(allOf(hasProperty("name", is("ifInOctets"))), allOf(hasProperty("name", is("ifSpeed")), hasProperty("value", is("1000")))));
assertThat(resourceStorageDao.exists(RESOURCE_PATH_RESPONSE, 0), is(true));
assertThat(resourceStorageDao.getAttributes(RESOURCE_PATH_RESPONSE), hasItems(allOf(hasProperty("name", is("icmp")))));
final Results<Measurement> result = repository.select(Context.DEFAULT_CONTEXT, new Resource(NewtsUtils.toResourceId(ResourcePath.get(RESOURCE_PATH_SNMP, "mib2-interfaces"))), Optional.of(Timestamp.fromEpochSeconds(1414504800)), Optional.of(Timestamp.fromEpochSeconds(1417047045)), new ResultDescriptor(Duration.seconds(7200)).datasource("ifInOctets", StandardAggregationFunctions.AVERAGE).export("ifInOctets"), Optional.of(Duration.seconds(7200)));
assertThat(result.getRows().size(), is(EXPECTED_DATA.length));
int i = 0;
for (Results.Row<Measurement> r : result) {
final double deltaAbs = r.getElement("ifInOctets").getValue().doubleValue() - EXPECTED_DATA[i].value;
final double deltaRel = deltaAbs / EXPECTED_DATA[i].value * 100.0;
/* Use the following for debugging of non-matching entries...
System.out.println(String.format(
"%4d: %-24s %11.2f %11.2f %11.2f (%6.2f) %36s|%-36s %f%%",
i,
r.getElement("ifInOctets").getTimestamp().asDate().toString(),
r.getElement("ifInOctets").getValue().doubleValue(),
EXPECTED_DATA[i].value,
deltaAbs,
deltaRel,
deltaAbs < -1.0 ? Strings.repeat("\u2592", (int) Math.abs(Math.log10(-deltaAbs) * 10.0)) : "",
deltaAbs > 1.0 ? Strings. repeat("\u2592", (int) Math.abs(Math.log10(deltaAbs) * 10.0)) : "",
Math.abs(deltaAbs / EXPECTED_DATA[i].value * 100.0)));
*/
assertThat(r.getTimestamp().asSeconds(), is(EXPECTED_DATA[i].timestamp));
if (i != 270) {
// We got some errors on the RRA boundaries - ignore them
assertThat(r.getElement("ifInOctets").getValue().doubleValue(), is(anyOf(equalTo(EXPECTED_DATA[i].value), // Allow a relative error of 0.3%
closeTo(EXPECTED_DATA[i].value, EXPECTED_DATA[i].value * 0.003))));
}
i++;
}
});
NewtsConverter.main("-o", OPENNMS_HOME.toString(), "-r", data.toString(), "-t", Boolean.toString(useRrdTool), "-T", RRD_BINARY.toAbsolutePath().toString(), "-s", Boolean.toString(storeByGroup));
}
use of org.opennms.newts.api.query.ResultDescriptor in project newts by OpenNMS.
the class ComputeTest method testBlacklist.
@Test(expected = JexlException.class)
public void testBlacklist() {
Iterator<Row<Measurement>> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 20).row(600).element("in", 60).build();
ResultDescriptor rDescriptor = new ResultDescriptor().datasource("in", "ifInOctets", seconds(600), AVERAGE).expression("sum", "in + in.class.hashCode()").export("sum");
Compute compute = new Compute(rDescriptor, testData);
while (compute.hasNext()) {
compute.next().getElement("sum");
}
}
use of org.opennms.newts.api.query.ResultDescriptor in project newts by OpenNMS.
the class PrimaryDataTest method testManyToOneSamples.
@Test
public void testManyToOneSamples() {
// Element interval is less than step size.
Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m0", 0).element("m1", 1).row(300).element("m0", 1).element("m1", 2).row(600).element("m0", 2).element("m1", 3).row(900).element("m0", 3).element("m1", 4).row(1200).element("m0", 4).element("m1", 5).row(1500).element("m0", 5).element("m1", 6).row(1800).element("m0", 6).element("m1", 7).row(2100).element("m0", 7).element("m1", 8).build();
// Minimal result descriptor
ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(900)).datasource("m0", "m0", Duration.seconds(1800), null).datasource("m1", "m1", Duration.seconds(1800), null);
// Expected results
Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900).element("m0", 2).element("m1", 3).row(1800).element("m0", 5).element("m1", 6).build();
PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(900), Timestamp.fromEpochSeconds(1800), rDescriptor, testData);
assertRowsEqual(expected, primaryData);
}
use of org.opennms.newts.api.query.ResultDescriptor in project newts by OpenNMS.
the class ResultProcessorTest method testCalculated.
@Test
public void testCalculated() {
Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.COUNTER).row(900000000).element("m0", 3000).element("m1", // Thu Jul 9 11:00:00 CDT 1998
3000).row(900000300).element("m0", 6000).element("m1", 6000).row(900000600).element("m0", 9000).element("m1", 9000).row(900000900).element("m0", 12000).element("m1", 12000).row(900001200).element("m0", 15000).element("m1", 15000).row(900001500).element("m0", 18000).element("m1", 18000).row(900001800).element("m0", 21000).element("m1", 21000).row(900002100).element("m0", 24000).element("m1", 24000).row(900002400).element("m0", 27000).element("m1", 27000).row(900002700).element("m0", 30000).element("m1", 30000).row(900003000).element("m0", 33000).element("m1", 33000).row(900003300).element("m0", 36000).element("m1", 36000).row(900003600).element("m0", 39000).element("m1", 39000).row(900003900).element("m0", 42000).element("m1", 42000).row(900004200).element("m0", 45000).element("m1", 45000).row(900004500).element("m0", 48000).element("m1", 48000).row(900004800).element("m0", 51000).element("m1", 51000).row(900005100).element("m0", 54000).element("m1", 54000).row(900005400).element("m0", 57000).element("m1", 57000).row(900005700).element("m0", 60000).element("m1", 60000).row(900006000).element("m0", 63000).element("m1", 63000).row(900006300).element("m0", 66000).element("m1", 66000).row(900006600).element("m0", 69000).element("m1", 69000).row(900006900).element("m0", 72000).element("m1", 72000).row(900007200).element("m0", 75000).element("m1", // Thu Jul 9 13:00:00 CDT 1998
75000).build();
// Function to add two values
BinaryFunction sum = new BinaryFunction() {
private static final long serialVersionUID = 0L;
@Override
public double apply(double a, double b) {
return a + b;
}
};
ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0", AVERAGE).datasource("m1", AVERAGE).calculate("total", sum, "m0", "m1").export("total");
Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900003600).element("total", 20).row(900007200).element("total", 20).build();
ResultProcessor processor = new ResultProcessor(new Resource("localhost"), Timestamp.fromEpochSeconds(900003600), Timestamp.fromEpochSeconds(900007200), rDescriptor, Duration.minutes(60));
assertRowsEqual(expected, processor.process(testData).iterator());
}
Aggregations