Search in sources :

Example 1 with UsageHistogramHandler

use of io.apiman.manager.api.jdbc.handlers.UsageHistogramHandler in project apiman by apiman.

the class JdbcMetricsAccessor method getUsage.

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

Aggregations

UsageDataPoint (io.apiman.manager.api.beans.metrics.UsageDataPoint)1 UsageHistogramBean (io.apiman.manager.api.beans.metrics.UsageHistogramBean)1 UsageHistogramHandler (io.apiman.manager.api.jdbc.handlers.UsageHistogramHandler)1 SQLException (java.sql.SQLException)1 QueryRunner (org.apache.commons.dbutils.QueryRunner)1