use of com.yahoo.dba.perf.myperf.common.ResultList in project mysql_perf_analyzer by yahoo.
the class MetricsDbBase method retrieveMetrics.
public ResultList retrieveMetrics(String metricGroupName, String[] metrics, boolean hasKeyColumn, int dbid, long startDate, long endDate) {
int[] snaps = this.getSnapshostRange(startDate, endDate);
//no data
if (snaps == null)
return null;
if (//not specify the metrics? Get all
metrics == null || metrics.length == 0)
return retrieveMetrics(metricGroupName, dbid, startDate, endDate);
//later, connection pooling
ResultList rList = null;
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
//build select list
StringBuilder sb = new StringBuilder();
sb.append("SNAP_ID");
if (hasKeyColumn)
sb.append(", KEY_COLUMN");
sb.append(", TS");
for (String me : metrics) {
sb.append(", ");
sb.append(me);
}
String sql = "select " + sb.toString() + " from " + metricGroupName + " where dbid=? and snap_id between ? and ? order by dbid, snap_id";
//String sql = "select * from "+metricGroupName+" where dbid=?";
logger.log(Level.INFO, "To retrieve metrics " + metricGroupName + ", metrics (" + sb.toString() + ") for db " + dbid + " with time range (" + startDate + ", " + endDate + "), snap (" + snaps[0] + ", " + snaps[1] + ")");
try {
conn = createConnection(true);
stmt = conn.prepareStatement(sql);
stmt.setFetchSize(1000);
//stmt.setMaxRows(5000);
stmt.setInt(1, dbid);
stmt.setInt(2, snaps[0]);
stmt.setInt(3, snaps[1]);
rs = stmt.executeQuery();
rList = ResultListUtil.fromSqlResultSet(rs, 5000);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Failed to retrieve metrics " + metricGroupName + " for db " + dbid + " with time range (" + startDate + ", " + endDate + ")", ex);
} finally {
DBUtils.close(stmt);
DBUtils.close(conn);
}
return rList;
}
Aggregations