Search in sources :

Example 31 with ResultList

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;
}
Also used : ResultList(com.yahoo.dba.perf.myperf.common.ResultList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Aggregations

ResultList (com.yahoo.dba.perf.myperf.common.ResultList)31 ResultRow (com.yahoo.dba.perf.myperf.common.ResultRow)22 ColumnDescriptor (com.yahoo.dba.perf.myperf.common.ColumnDescriptor)21 SQLException (java.sql.SQLException)17 ArrayList (java.util.ArrayList)10 Map (java.util.Map)9 ResultSet (java.sql.ResultSet)8 SNMPTriple (com.yahoo.dba.perf.myperf.snmp.SNMPClient.SNMPTriple)7 Connection (java.sql.Connection)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 DBInstanceInfo (com.yahoo.dba.perf.myperf.common.DBInstanceInfo)6 QueryParameters (com.yahoo.dba.perf.myperf.common.QueryParameters)6 PreparedStatement (java.sql.PreparedStatement)6 BigDecimal (java.math.BigDecimal)5 List (java.util.List)5 HashMap (java.util.HashMap)4 Statement (java.sql.Statement)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 ColumnInfo (com.yahoo.dba.perf.myperf.common.ColumnInfo)2