Search in sources :

Example 21 with ResultRow

use of com.yahoo.dba.perf.myperf.common.ResultRow in project mysql_perf_analyzer by yahoo.

the class TableMetaProcessor method queryMultiple.

@Override
public void queryMultiple(MyPerfContext context, DBInstanceInfo dbinfo, String appUser, DBConnectionWrapper connWrapper, QueryParameters qps, Map<String, ResultList> rListMap) throws java.sql.SQLException {
    for (int i = 0; i < TBL_QUERIES.length; i++) {
        QueryParameters qps2 = new QueryParameters();
        qps2.setSql(TBL_QUERIES[i]);
        qps2.getSqlParams().put("p_1", qps.getSqlParams().get("p_1"));
        qps2.getSqlParams().put("p_2", qps.getSqlParams().get("p_2"));
        ResultList rList = null;
        try {
            rList = context.getQueryEngine().executeQueryGeneric(qps2, connWrapper, qps.getMaxRows());
        } catch (Throwable th) {
            logger.log(Level.WARNING, "Error when retrieve meta data", th);
            if (th instanceof SQLException) {
                //check if the connection is still good
                if (!DBUtils.checkConnection(connWrapper.getConnection())) {
                    throw SQLException.class.cast(th);
                }
            }
            Sql sql = context.getSqlManager().getSql(qps2.getSql());
            if (sql != null && sql.isErrorInline()) {
                rList = new ResultList();
                ColumnDescriptor desc = new ColumnDescriptor();
                desc.addColumn("Status", false, 0);
                desc.addColumn("Message", false, 1);
                rList.setColumnDescriptor(desc);
                ResultRow row = new ResultRow();
                row.setColumnDescriptor(desc);
                row.addColumn("Error");
                row.addColumn(th.getMessage());
                rList.addRow(row);
            }
        }
        rListMap.put(TBL_QUERIES[i], rList);
    }
}
Also used : ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) SQLException(java.sql.SQLException) ColumnDescriptor(com.yahoo.dba.perf.myperf.common.ColumnDescriptor) QueryParameters(com.yahoo.dba.perf.myperf.common.QueryParameters) Sql(com.yahoo.dba.perf.myperf.common.Sql)

Example 22 with ResultRow

use of com.yahoo.dba.perf.myperf.common.ResultRow in project mysql_perf_analyzer by yahoo.

the class ReplShowProcessor method addOutputRow.

private void addOutputRow(ReplStatus rpl, ResultList rList, int level) {
    ResultRow row = new ResultRow();
    String prefix = "";
    if (level > 0) {
        for (int i = 0; i < level; i++) {
            prefix += "-";
        }
    }
    row.addColumn(prefix + rpl.hostname + ":" + rpl.port);
    if (rpl.masterHost != null && !rpl.masterHost.isEmpty())
        row.addColumn(rpl.masterHost + ":" + rpl.masterPort);
    else
        row.addColumn(null);
    row.addColumn(rpl.lag);
    if (rpl.io != null || rpl.sql != null)
        row.addColumn(rpl.io + "/" + rpl.sql);
    else
        row.addColumn(null);
    if (rpl.masterFile != null)
        row.addColumn(rpl.masterFile + ":" + rpl.masterPosition);
    else
        row.addColumn(null);
    row.addColumn(rpl.masterLogFile);
    row.addColumn(rpl.readMasterLogPos);
    row.addColumn(rpl.relayMasterLogFile);
    row.addColumn(rpl.execMasterLogPos);
    row.addColumn(rpl.masterExecutedGtidSet);
    row.addColumn(rpl.executedGtidSet);
    row.setColumnDescriptor(rList.getColumnDescriptor());
    rList.addRow(row);
}
Also used : ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow)

Example 23 with ResultRow

use of com.yahoo.dba.perf.myperf.common.ResultRow in project mysql_perf_analyzer by yahoo.

the class MetricsDbBase method retrieveAlerts.

/**
	   * 
	   * @param startTs
	   * @param endTs
	   * @param dbs a map for look up db info by dbis
	   * @param filteredDbs actual dbs to retrieve alerts
	   * @return
	   */
public ResultList retrieveAlerts(String startTs, String endTs, Map<Integer, DBInstanceInfo> dbs, List<Integer> filteredDbs) {
    ResultList rList = null;
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    rList = new ResultList();
    ColumnDescriptor desc = new ColumnDescriptor();
    desc.addColumn("DBGROUP", false, 1);
    desc.addColumn("HOST", false, 2);
    desc.addColumn("TS", false, 3);
    desc.addColumn("END_TS", false, 4);
    desc.addColumn("ALERT_TYPE", false, 5);
    desc.addColumn("ALERT_REASON", false, 6);
    desc.addColumn("BY CPU", true, 7);
    desc.addColumn("BY IO", true, 8);
    desc.addColumn("BY THREAD", true, 9);
    desc.addColumn("BY LOADAVG", true, 10);
    desc.addColumn("BY REPL LAG", true, 11);
    desc.addColumn("BY SLOW QUERY", true, 12);
    desc.addColumn("BY REPL DOWN", true, 13);
    desc.addColumn("BY CONN FAILURE", true, 14);
    desc.addColumn("BY DEADLOCKS", true, 15);
    rList.setColumnDescriptor(desc);
    StringBuilder sb = new StringBuilder();
    sb.append("select * from ALERT where ts between ").append(startTs).append(" and ").append(endTs);
    if (filteredDbs != null && filteredDbs.size() >= 1) {
        sb.append(" and dbid in (");
        boolean isFirst = true;
        for (Integer id : filteredDbs) {
            if (!isFirst)
                sb.append(",");
            sb.append(id);
            isFirst = false;
        }
        sb.append(")");
    }
    sb.append(" order by ts desc");
    String sql = sb.toString();
    logger.log(Level.INFO, "Retrieve alerts: " + sql);
    Map<Integer, AlertSummary> sumMap = null;
    try {
        conn = createConnection(true);
        sumMap = this.retrieve7DaysAlertsSummary(conn, filteredDbs);
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
        //DBID, TS, END_TS, ALERT_TYPE, ALERT_REASON
        while (rs != null && rs.next()) {
            int dbid = rs.getInt("DBID");
            if (!dbs.containsKey(dbid))
                //no db records, ignore
                continue;
            DBInstanceInfo dbinfo = dbs.get(dbid);
            ResultRow row = new ResultRow();
            row.setColumnDescriptor(desc);
            row.addColumn(dbinfo.getDbGroupName());
            row.addColumn(dbinfo.getHostName());
            row.addColumn(formatDatetime(rs.getString("TS")));
            row.addColumn(formatDatetime(rs.getString("END_TS")));
            row.addColumn(rs.getString("ALERT_TYPE"));
            row.addColumn(rs.getString("ALERT_REASON"));
            //don't expect missing
            AlertSummary sum = sumMap.get(dbid);
            row.addColumn(sum != null ? String.valueOf(sum.cpuAlerts) : "0");
            row.addColumn(sum != null ? String.valueOf(sum.ioAlerts) : "0");
            row.addColumn(sum != null ? String.valueOf(sum.threadAlerts) : "0");
            row.addColumn(sum != null ? String.valueOf(sum.LoadAvgAlerts) : "0");
            row.addColumn(sum != null ? String.valueOf(sum.replAlerts) : "0");
            row.addColumn(sum != null ? String.valueOf(sum.slowAlerts) : "0");
            row.addColumn(sum != null ? String.valueOf(sum.replDown) : "0");
            row.addColumn(sum != null ? String.valueOf(sum.connectFailuerAlerts) : "0");
            row.addColumn(sum != null ? String.valueOf(sum.deadlocks) : "0");
            rList.addRow(row);
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Failed to retrieve alerts " + sql, ex);
    } finally {
        DBUtils.close(rs);
        DBUtils.close(stmt);
        DBUtils.close(conn);
    }
    return rList;
}
Also used : ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ColumnDescriptor(com.yahoo.dba.perf.myperf.common.ColumnDescriptor) Connection(java.sql.Connection) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo)

Aggregations

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