use of org.opennms.netmgt.measurements.model.QueryRequest 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.QueryRequest 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.QueryRequest 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.QueryRequest in project opennms by OpenNMS.
the class MeasurementsRestServiceITCase method cannotRetrieveUnknownAttributeAndUnknownFallbackAttribute.
@Test(expected = javax.ws.rs.WebApplicationException.class)
public void cannotRetrieveUnknownAttributeAndUnknownFallbackAttribute() {
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("willNotBeFound");
ifInOctetsAvg.setFallbackAttribute("willNotBeFoundToo");
ifInOctetsAvg.setAggregation("AVERAGE");
ifInOctetsAvg.setLabel("ifInOctetsAvg");
request.setSources(Lists.newArrayList(ifInOctetsAvg));
// Perform the query - this must fail
m_svc.query(request);
}
use of org.opennms.netmgt.measurements.model.QueryRequest in project opennms by OpenNMS.
the class MeasurementsRestServiceITCase method buildRequest.
private static QueryRequest buildRequest() {
final QueryRequest request = new QueryRequest();
request.setStart(1414602000000L);
request.setEnd(1417046400000L);
request.setStep(1000L);
final Source source = new Source();
source.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
source.setAttribute("ifInOctets");
source.setAggregation("AVERAGE");
source.setLabel("octetsIn");
request.setSources(Lists.newArrayList(source));
return request;
}
Aggregations