use of org.opennms.netmgt.measurements.model.QueryResponse in project opennms by OpenNMS.
the class LocalMeasurementDataSourceWrapper method createDataSource.
@Override
public JRRewindableDataSource createDataSource(String query) throws JRException {
Objects.requireNonNull(query);
QueryRequest queryRequest = unmarshal(query);
Objects.requireNonNull(queryRequest);
// Enforce relaxed mode
queryRequest.setRelaxed(true);
try {
QueryResponse response = fetchService.query(queryRequest);
return new MeasurementDataSource(response);
} catch (ResourceNotFoundException rnfe) {
LOG.warn("A attribute or resource was not found", rnfe);
return new EmptyJRDataSource();
} catch (Exception e) {
LOG.error("An error occurred while fetching the measurement results", e);
throw new JRException(e);
}
}
use of org.opennms.netmgt.measurements.model.QueryResponse in project opennms by OpenNMS.
the class MeasurementsRestServiceWithRrdIT method canRetrieveMeasurementsFromRrd.
@Test
public void canRetrieveMeasurementsFromRrd() throws Exception {
QueryRequest request = new QueryRequest();
request.setStart(1414602000000L);
request.setEnd(1417046400000L);
request.setStep(1000L);
request.setMaxRows(700);
// Average
Source ifInOctetsAvg = new Source();
ifInOctetsAvg.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
ifInOctetsAvg.setAttribute("ifInOctets");
ifInOctetsAvg.setAggregation("AVERAGE");
ifInOctetsAvg.setLabel("ifInOctetsAvg");
// Min
Source ifInOctetsMin = new Source();
ifInOctetsMin.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
ifInOctetsMin.setAttribute("ifInOctets");
ifInOctetsMin.setAggregation("MIN");
ifInOctetsMin.setLabel("ifInOctetsMin");
// Max
Source ifInOctetsMax = new Source();
ifInOctetsMax.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
ifInOctetsMax.setAttribute("ifInOctets");
ifInOctetsMax.setAggregation("MAX");
ifInOctetsMax.setLabel("ifInOctetsMax");
request.setSources(Lists.newArrayList(ifInOctetsAvg, ifInOctetsMin, ifInOctetsMax));
// Perform the query
QueryResponse response = m_svc.query(request);
// Validate the results
long[] timestamps = response.getTimestamps();
final Map<String, double[]> columns = response.columnsWithLabels();
assertEquals(3600000L, response.getStep());
assertEquals(680, timestamps.length);
// Verify the values at an arbitrary index
final int idx = 8;
assertEquals(1414630800000L, timestamps[idx]);
assertEquals(270.66140826873385, columns.get("ifInOctetsAvg")[idx], 0.0001);
assertEquals(259.54086378737543, columns.get("ifInOctetsMin")[idx], 0.0001);
assertEquals(67872.22455490529, columns.get("ifInOctetsMax")[idx], 0.0001);
}
use of org.opennms.netmgt.measurements.model.QueryResponse in project opennms by OpenNMS.
the class MeasurementsRestServiceWithJrbIT method canApplyFilters.
@Test
public void canApplyFilters() {
QueryRequest request = new QueryRequest();
request.setStart(1414602000000L);
request.setEnd(1418046400000L);
request.setStep(1000L);
request.setMaxRows(700);
Source ifInOctets = new Source();
ifInOctets.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
ifInOctets.setAttribute("ifInOctets");
ifInOctets.setAggregation("MAX");
ifInOctets.setLabel("ifInOctets");
request.setSources(Lists.newArrayList(ifInOctets));
// Apply a chomp filter - cutting some of the first row off, and the trailing NaNs
FilterDef chompFilter = new FilterDef("Chomp", "cutoffDate", "1414630000.0", "stripNaNs", "true");
request.setFilters(Lists.newArrayList(chompFilter));
LOG.debug(JaxbUtils.marshal(request));
QueryResponse response = m_svc.query(request);
// Verify the values for the first and last rows
final Map<String, double[]> columns = response.columnsWithLabels();
double[] ifInOctetsColumn = columns.get("ifInOctets");
assertEquals(67872.22455490529, ifInOctetsColumn[0], 0.0001);
assertEquals(1649961.9593111263, ifInOctetsColumn[ifInOctetsColumn.length - 1], 0.0001);
}
use of org.opennms.netmgt.measurements.model.QueryResponse in project opennms by OpenNMS.
the class MeasurementsRestServiceWithJrbIT method canRetrieveMeasurementsFromJrb.
@Test
public void canRetrieveMeasurementsFromJrb() {
QueryRequest request = new QueryRequest();
request.setStart(1414602000000L);
request.setEnd(1417046400000L);
request.setStep(1000L);
request.setMaxRows(700);
// Average
Source ifInOctetsAvg = new Source();
ifInOctetsAvg.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
ifInOctetsAvg.setAttribute("ifInOctets");
ifInOctetsAvg.setAggregation("AVERAGE");
ifInOctetsAvg.setLabel("ifInOctetsAvg");
// Min
Source ifInOctetsMin = new Source();
ifInOctetsMin.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
ifInOctetsMin.setAttribute("ifInOctets");
ifInOctetsMin.setAggregation("MIN");
ifInOctetsMin.setLabel("ifInOctetsMin");
// Max
Source ifInOctetsMax = new Source();
ifInOctetsMax.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
ifInOctetsMax.setAttribute("ifInOctets");
ifInOctetsMax.setAggregation("MAX");
ifInOctetsMax.setLabel("ifInOctetsMax");
request.setSources(Lists.newArrayList(ifInOctetsAvg, ifInOctetsMin, ifInOctetsMax));
// Perform the query
QueryResponse response = m_svc.query(request);
// Validate the results
long[] timestamps = response.getTimestamps();
final Map<String, double[]> columns = response.columnsWithLabels();
assertEquals(3600000L, response.getStep());
assertEquals(680, timestamps.length);
// Verify the values at an arbitrary index
final int idx = 8;
assertEquals(1414630800000L, timestamps[idx]);
assertEquals(270.66140826873385, columns.get("ifInOctetsAvg")[idx], 0.0001);
assertEquals(259.54086378737543, columns.get("ifInOctetsMin")[idx], 0.0001);
assertEquals(67872.22455490529, columns.get("ifInOctetsMax")[idx], 0.0001);
}
use of org.opennms.netmgt.measurements.model.QueryResponse in project opennms by OpenNMS.
the class DefaultMeasurementsService method query.
@Override
public QueryResponse query(QueryRequest request) throws MeasurementException {
validate(request);
// Fetch the measurements
FetchResults results;
try {
results = fetchStrategy.fetch(request.getStart(), request.getEnd(), request.getStep(), request.getMaxRows(), request.getHeartbeat(), request.getInterval(), request.getSources(), request.isRelaxed());
} catch (Exception e) {
throw new FetchException(e, "Fetch failed: {}", e.getMessage());
}
if (results == null) {
throw new ResourceNotFoundException(request);
}
// Apply the expression to the fetch results
expressionEngine.applyExpressions(request, results);
// Apply the filters
if (!request.getFilters().isEmpty()) {
RowSortedTable<Long, String, Double> table = results.asRowSortedTable();
filterEngine.filter(request.getFilters(), table);
results = new FetchResults(table, results.getStep(), results.getConstants());
}
// Remove any transient values belonging to sources
final Map<String, double[]> columns = results.getColumns();
for (final Source source : request.getSources()) {
if (source.getTransient()) {
columns.remove(source.getLabel());
}
}
// Build the response
final QueryResponse response = new QueryResponse();
response.setStart(request.getStart());
response.setEnd(request.getEnd());
response.setStep(results.getStep());
response.setTimestamps(results.getTimestamps());
response.setColumns(results.getColumns());
response.setConstants(results.getConstants());
return response;
}
Aggregations