Search in sources :

Example 1 with ResponseStatsDataPoint

use of io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint in project apiman by apiman.

the class JdbcMetricsAccessor method getResponseStats.

/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getResponseStats(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.metrics.HistogramIntervalType, org.joda.time.DateTime, org.joda.time.DateTime)
 */
@Override
public ResponseStatsHistogramBean getResponseStats(String organizationId, String apiId, String version, HistogramIntervalType interval, DateTime from, DateTime to) {
    ResponseStatsHistogramBean rval = new ResponseStatsHistogramBean();
    Map<Long, ResponseStatsDataPoint> index = MetricsAccessorHelper.generateHistogramSkeleton(rval, from, to, interval, ResponseStatsDataPoint.class, Long.class);
    try {
        QueryRunner run = new QueryRunner(ds);
        String gbColumn = groupByColumn(interval);
        // $NON-NLS-1$ //$NON-NLS-2$
        String sql = "SELECT " + gbColumn + ", resp_type, count(*) FROM gw_requests WHERE api_org_id = ? AND api_id = ? AND api_version = ? AND rstart >= ? AND rstart < ? GROUP BY resp_type," + gbColumn;
        ResultSetHandler<ResponseStatsHistogramBean> handler = new ResponseStatsHistogramHandler(rval, index);
        run.query(sql, handler, organizationId, apiId, version, from.getMillis(), to.getMillis());
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return rval;
}
Also used : ResponseStatsHistogramBean(io.apiman.manager.api.beans.metrics.ResponseStatsHistogramBean) ResponseStatsDataPoint(io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint) ResponseStatsHistogramHandler(io.apiman.manager.api.jdbc.handlers.ResponseStatsHistogramHandler) SQLException(java.sql.SQLException) QueryRunner(org.apache.commons.dbutils.QueryRunner)

Example 2 with ResponseStatsDataPoint

use of io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint in project apiman by apiman.

the class ResponseStatsHistogramHandler method handle.

/**
 * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
 */
@Override
public ResponseStatsHistogramBean handle(ResultSet rs) throws SQLException {
    while (rs.next()) {
        long time = rs.getLong(1);
        String rtype = rs.getString(2);
        long count = rs.getLong(3);
        ResponseStatsDataPoint dataPoint = index.get(time);
        if (dataPoint != null) {
            if (rtype == null) {
                dataPoint.setTotal(dataPoint.getErrors() + dataPoint.getFailures() + count);
            } else if (rtype.equals("failure")) {
                // $NON-NLS-1$
                dataPoint.setTotal(dataPoint.getTotal() + count);
                dataPoint.setFailures(count);
            } else if (rtype.equals("error")) {
                // $NON-NLS-1$
                dataPoint.setTotal(dataPoint.getTotal() + count);
                dataPoint.setErrors(count);
            }
        }
    }
    return histogram;
}
Also used : ResponseStatsDataPoint(io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint)

Example 3 with ResponseStatsDataPoint

use of io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint in project apiman by apiman.

the class JdbcMetricsAccessorTest method testGetResponseStats.

/**
 * Test method for {@link io.apiman.manager.api.jdbc.JdbcMetricsAccessor#getResponseStats(String, String, String, HistogramIntervalType, DateTime, DateTime)}.
 */
@Test
public void testGetResponseStats() {
    Map<String, String> config = new HashMap<>();
    config.put("datasource.jndi-location", DB_JNDI_LOC);
    JdbcMetricsAccessor accessor = new JdbcMetricsAccessor(config);
    DateTime from = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).parseDateTime("2016-01-01T00:00:00Z");
    DateTime to = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).parseDateTime("2016-12-31T00:00:00Z");
    ResponseStatsHistogramBean stats = accessor.getResponseStats("TestOrg", "TestApi", "1.0", HistogramIntervalType.month, from, to);
    Assert.assertNotNull(stats);
    for (ResponseStatsDataPoint dataPoint : stats.getData()) {
        if (dataPoint.getLabel().equals("2016-02-01T00:00:00.000Z")) {
            Assert.assertEquals(18, dataPoint.getTotal());
            Assert.assertEquals(1, dataPoint.getErrors());
            Assert.assertEquals(3, dataPoint.getFailures());
        } else {
            Assert.assertEquals(0, dataPoint.getTotal());
            Assert.assertEquals(0, dataPoint.getErrors());
            Assert.assertEquals(0, dataPoint.getFailures());
        }
    }
    from = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).parseDateTime("2016-02-01T00:00:00Z");
    to = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).parseDateTime("2016-03-01T00:00:00Z");
    stats = accessor.getResponseStats("TestOrg", "TestApi", "1.0", HistogramIntervalType.day, from, to);
    Assert.assertNotNull(stats);
    ResponseStatsDataPoint dataPoint = stats.getData().get(9);
    Assert.assertEquals(2, dataPoint.getTotal());
    Assert.assertEquals(0, dataPoint.getErrors());
    Assert.assertEquals(0, dataPoint.getFailures());
    dataPoint = stats.getData().get(10);
    Assert.assertEquals(1, dataPoint.getTotal());
    Assert.assertEquals(0, dataPoint.getErrors());
    Assert.assertEquals(0, dataPoint.getFailures());
    dataPoint = stats.getData().get(22);
    Assert.assertEquals(9, dataPoint.getTotal());
    Assert.assertEquals(1, dataPoint.getErrors());
    Assert.assertEquals(1, dataPoint.getFailures());
    dataPoint = stats.getData().get(23);
    Assert.assertEquals(6, dataPoint.getTotal());
    Assert.assertEquals(0, dataPoint.getErrors());
    Assert.assertEquals(2, dataPoint.getFailures());
    dataPoint = stats.getData().get(5);
    Assert.assertEquals(0, dataPoint.getTotal());
    Assert.assertEquals(0, dataPoint.getErrors());
    Assert.assertEquals(0, dataPoint.getFailures());
    dataPoint = stats.getData().get(19);
    Assert.assertEquals(0, dataPoint.getTotal());
    Assert.assertEquals(0, dataPoint.getErrors());
    Assert.assertEquals(0, dataPoint.getFailures());
}
Also used : ResponseStatsHistogramBean(io.apiman.manager.api.beans.metrics.ResponseStatsHistogramBean) ResponseStatsDataPoint(io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 4 with ResponseStatsDataPoint

use of io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint in project apiman by apiman.

the class ResponseStatsPerClientHandler method handle.

/**
 * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
 */
@Override
public ResponseStatsPerClientBean handle(ResultSet rs) throws SQLException {
    ResponseStatsPerClientBean rval = new ResponseStatsPerClientBean();
    while (rs.next()) {
        String client = rs.getString(1);
        if (client == null) {
            continue;
        }
        String rtype = rs.getString(2);
        long count = rs.getLong(3);
        ResponseStatsDataPoint dataPoint = rval.getData().get(client);
        if (dataPoint == null) {
            dataPoint = new ResponseStatsDataPoint();
            rval.getData().put(client, dataPoint);
        }
        if (rtype == null) {
            dataPoint.setTotal(dataPoint.getErrors() + dataPoint.getFailures() + count);
        } else if (rtype.equals("failure")) {
            // $NON-NLS-1$
            dataPoint.setTotal(dataPoint.getTotal() + count);
            dataPoint.setFailures(count);
        } else if (rtype.equals("error")) {
            // $NON-NLS-1$
            dataPoint.setTotal(dataPoint.getTotal() + count);
            dataPoint.setErrors(count);
        }
    }
    return rval;
}
Also used : ResponseStatsPerClientBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerClientBean) ResponseStatsDataPoint(io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint)

Example 5 with ResponseStatsDataPoint

use of io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint in project apiman by apiman.

the class ResponseStatsPerPlanHandler method handle.

/**
 * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
 */
@Override
public ResponseStatsPerPlanBean handle(ResultSet rs) throws SQLException {
    ResponseStatsPerPlanBean rval = new ResponseStatsPerPlanBean();
    while (rs.next()) {
        String plan = rs.getString(1);
        if (plan == null) {
            continue;
        }
        String rtype = rs.getString(2);
        long count = rs.getLong(3);
        ResponseStatsDataPoint dataPoint = rval.getData().get(plan);
        if (dataPoint == null) {
            dataPoint = new ResponseStatsDataPoint();
            rval.getData().put(plan, dataPoint);
        }
        if (rtype == null) {
            dataPoint.setTotal(dataPoint.getErrors() + dataPoint.getFailures() + count);
        } else if (rtype.equals("failure")) {
            // $NON-NLS-1$
            dataPoint.setTotal(dataPoint.getTotal() + count);
            dataPoint.setFailures(count);
        } else if (rtype.equals("error")) {
            // $NON-NLS-1$
            dataPoint.setTotal(dataPoint.getTotal() + count);
            dataPoint.setErrors(count);
        }
    }
    return rval;
}
Also used : ResponseStatsPerPlanBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerPlanBean) ResponseStatsDataPoint(io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint)

Aggregations

ResponseStatsDataPoint (io.apiman.manager.api.beans.metrics.ResponseStatsDataPoint)8 HashMap (java.util.HashMap)4 ResponseStatsHistogramBean (io.apiman.manager.api.beans.metrics.ResponseStatsHistogramBean)3 DateTime (org.joda.time.DateTime)3 Test (org.junit.Test)3 ResponseStatsPerClientBean (io.apiman.manager.api.beans.metrics.ResponseStatsPerClientBean)2 ResponseStatsPerPlanBean (io.apiman.manager.api.beans.metrics.ResponseStatsPerPlanBean)2 ResponseStatsHistogramHandler (io.apiman.manager.api.jdbc.handlers.ResponseStatsHistogramHandler)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 QueryRunner (org.apache.commons.dbutils.QueryRunner)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 ParsedFilter (org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter)1 ParsedDateHistogram (org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram)1