Search in sources :

Example 1 with QueryRequest

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);
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) Source(org.opennms.netmgt.measurements.model.Source) Test(org.junit.Test)

Example 2 with QueryRequest

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);
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) FilterDef(org.opennms.netmgt.measurements.model.FilterDef) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) Source(org.opennms.netmgt.measurements.model.Source) Test(org.junit.Test)

Example 3 with QueryRequest

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);
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) QueryResponse(org.opennms.netmgt.measurements.model.QueryResponse) Source(org.opennms.netmgt.measurements.model.Source) Test(org.junit.Test)

Example 4 with QueryRequest

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);
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) Source(org.opennms.netmgt.measurements.model.Source) Test(org.junit.Test)

Example 5 with QueryRequest

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;
}
Also used : QueryRequest(org.opennms.netmgt.measurements.model.QueryRequest) Source(org.opennms.netmgt.measurements.model.Source)

Aggregations

QueryRequest (org.opennms.netmgt.measurements.model.QueryRequest)21 Test (org.junit.Test)13 Source (org.opennms.netmgt.measurements.model.Source)13 QueryResponse (org.opennms.netmgt.measurements.model.QueryResponse)7 Expression (org.opennms.netmgt.measurements.model.Expression)3 JRException (net.sf.jasperreports.engine.JRException)2 EmptyJRDataSource (org.opennms.netmgt.jasper.measurement.EmptyJRDataSource)2 MeasurementDataSource (org.opennms.netmgt.jasper.measurement.MeasurementDataSource)2 Request (com.github.tomakehurst.wiremock.http.Request)1 LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)1