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;
}
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;
}
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());
}
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;
}
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;
}
Aggregations