Search in sources :

Example 11 with DBInstanceInfo

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

the class InnoController method handleRequestImpl.

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    int status = Constants.STATUS_OK;
    String message = "OK";
    String group = req.getParameter("group");
    String host = req.getParameter("host");
    QueryParameters qps = new QueryParameters();
    qps.setGroup(group);
    qps.setHost(host);
    qps.setSql("mysql_innodb_engine_status");
    ResultList rList = null;
    LinkedHashMap<String, ResultList> listMap = new LinkedHashMap<String, ResultList>();
    DBInstanceInfo dbinfo = null;
    DBConnectionWrapper connWrapper = null;
    try {
        dbinfo = this.frameworkContext.getDbInfoManager().findDB(group, host).copy();
        connWrapper = WebAppUtil.getDBConnection(req, this.frameworkContext, dbinfo);
        if (connWrapper == null) {
            status = Constants.STATUS_BAD;
            message = "failed to connect to target db (" + dbinfo + ")";
        } else {
            rList = this.frameworkContext.getQueryEngine().executeQueryGeneric(qps, connWrapper, qps.getMaxRows());
            logger.info("Done query " + qps.getSql() + " with " + (rList != null ? rList.getRows().size() : 0) + " records.");
            if (rList != null && rList.getRows().size() > 0) {
                logger.info(rList.getRows().get(0).getColumns().get(rList.getRows().get(0).getColumns().size() - 1));
                listMap = parse(rList.getRows().get(0).getColumns().get(rList.getRows().get(0).getColumns().size() - 1));
            }
            WebAppUtil.closeDBConnection(req, connWrapper, false, this.getFrameworkContext().getMyperfConfig().isReuseMonUserConnction());
        }
    } catch (Throwable th) {
        logger.log(Level.SEVERE, "Exception", th);
        if (th instanceof SQLException) {
            SQLException sqlEx = SQLException.class.cast(th);
            String msg = th.getMessage();
            logger.info(sqlEx.getSQLState() + ", " + sqlEx.getErrorCode() + ", " + msg);
            //check if the connection is still good
            if (!DBUtils.checkConnection(connWrapper.getConnection())) {
                WebAppUtil.closeDBConnection(req, connWrapper, true, false);
            } else
                WebAppUtil.closeDBConnection(req, connWrapper, true, false);
        } else {
            if (connWrapper != null)
                WebAppUtil.closeDBConnection(req, connWrapper, false, this.getFrameworkContext().getMyperfConfig().isReuseMonUserConnction());
        }
        status = Constants.STATUS_BAD;
        message = "Exception: " + th.getMessage();
    } finally {
    }
    ModelAndView mv = new ModelAndView(this.jsonView);
    if (req.getParameter("callback") != null && req.getParameter("callback").trim().length() > 0)
        //YUI datasource binding
        mv.addObject("callback", req.getParameter("callback"));
    mv = new ModelAndView(this.jsonView);
    mv.addObject("json_result", ResultListUtil.toMultiListJSONStringUpper(listMap, qps, status, message));
    return mv;
}
Also used : ResultList(com.yahoo.dba.perf.myperf.common.ResultList) SQLException(java.sql.SQLException) ModelAndView(org.springframework.web.servlet.ModelAndView) QueryParameters(com.yahoo.dba.perf.myperf.common.QueryParameters) DBConnectionWrapper(com.yahoo.dba.perf.myperf.db.DBConnectionWrapper) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with DBInstanceInfo

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

the class MetricsDbBase method retrieveDBInfo.

private DBInstanceInfo retrieveDBInfo(Connection conn, String dbGroupName, String hostName) {
    String sql = "select * from " + DBINFO_TABLENAME + " where dbgroupname=? and hostname=?";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, dbGroupName.toLowerCase());
        pstmt.setString(2, hostName.toLowerCase());
        rs = pstmt.executeQuery();
        if (rs != null && rs.next()) {
            DBInstanceInfo dbinfo = new DBInstanceInfo();
            dbinfo.setDbid(rs.getInt("DBID"));
            dbinfo.setDbType(rs.getString("DBTYPE"));
            dbinfo.setDbGroupName(rs.getString("DBGROUPNAME"));
            dbinfo.setInstance(rs.getShort("INSTANCE"));
            dbinfo.setHostName(rs.getString("HOSTNAME"));
            dbinfo.setPort(rs.getString("PORT"));
            dbinfo.setDatabaseName(rs.getString("DATABASE_NAME"));
            dbinfo.setUseTunneling(rs.getShort("USE_SSHTUNNEL") == 1 ? true : false);
            dbinfo.setLocalHostName(rs.getString("LOCAL_HOSTNAME"));
            dbinfo.setLocalPort(rs.getString("LOCAL_PORT"));
            dbinfo.setConnectionVerified(1 == rs.getInt("CONNECTION_VERIFIED"));
            dbinfo.setVirtualHost(rs.getShort("VIRTUAL_HOST") == 1 ? true : false);
            dbinfo.setSnmpEnabled(rs.getShort("SNMP_ENABLED") == 1 ? true : false);
            dbinfo.setMetricsEnabled(rs.getShort("METRICS_ENABLED") == 1 ? true : false);
            dbinfo.setAlertEnabled(rs.getShort("ALERT_ENABLED") == 1 ? true : false);
            dbinfo.setOwner(rs.getString("OWNER"));
            return dbinfo;
        }
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Exception", ex);
    } finally {
        DBUtils.close(rs);
        DBUtils.close(pstmt);
    }
    return null;
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo) SQLException(java.sql.SQLException)

Example 13 with DBInstanceInfo

use of com.yahoo.dba.perf.myperf.common.DBInstanceInfo 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)

Example 14 with DBInstanceInfo

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

the class MetricsDbBase method loadDbInfo.

public java.util.Map<Integer, DBInstanceInfo> loadDbInfo(Connection conn) {
    String sql = "select * from " + DBINFO_TABLENAME;
    Statement stmt = null;
    ResultSet rs = null;
    java.util.Map<Integer, DBInstanceInfo> dbMap = new java.util.HashMap<Integer, DBInstanceInfo>();
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs != null && rs.next()) {
            DBInstanceInfo dbinfo = new DBInstanceInfo();
            dbinfo.setDbid(rs.getInt("DBID"));
            dbinfo.setDbType(rs.getString("DBTYPE"));
            dbinfo.setDbGroupName(rs.getString("DBGROUPNAME"));
            dbinfo.setInstance(rs.getShort("INSTANCE"));
            dbinfo.setHostName(rs.getString("HOSTNAME"));
            dbinfo.setPort(rs.getString("PORT"));
            dbinfo.setDatabaseName(rs.getString("DATABASE_NAME"));
            dbinfo.setUseTunneling(rs.getShort("USE_SSHTUNNEL") == 1 ? true : false);
            dbinfo.setLocalHostName(rs.getString("LOCAL_HOSTNAME"));
            dbinfo.setLocalPort(rs.getString("LOCAL_PORT"));
            dbinfo.setConnectionVerified(rs.getInt("CONNECTION_VERIFIED") == 1);
            dbinfo.setVirtualHost(rs.getInt("VIRTUAL_HOST") == 1);
            dbinfo.setSnmpEnabled(rs.getShort("SNMP_ENABLED") == 1 ? true : false);
            dbinfo.setMetricsEnabled(rs.getShort("METRICS_ENABLED") == 1 ? true : false);
            dbinfo.setAlertEnabled(rs.getShort("ALERT_ENABLED") == 1 ? true : false);
            dbinfo.setOwner(rs.getString("OWNER"));
            dbMap.put(dbinfo.getDbid(), dbinfo);
        }
    } catch (Exception ex) {
    } finally {
        DBUtils.close(rs);
        DBUtils.close(stmt);
    }
    return dbMap;
}
Also used : HashMap(java.util.HashMap) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo) SQLException(java.sql.SQLException)

Aggregations

DBInstanceInfo (com.yahoo.dba.perf.myperf.common.DBInstanceInfo)14 SQLException (java.sql.SQLException)10 ResultSet (java.sql.ResultSet)8 Map (java.util.Map)8 Statement (java.sql.Statement)7 HashMap (java.util.HashMap)7 ResultList (com.yahoo.dba.perf.myperf.common.ResultList)6 ArrayList (java.util.ArrayList)6 ResultRow (com.yahoo.dba.perf.myperf.common.ResultRow)5 ColumnDescriptor (com.yahoo.dba.perf.myperf.common.ColumnDescriptor)4 QueryParameters (com.yahoo.dba.perf.myperf.common.QueryParameters)4 DBConnectionWrapper (com.yahoo.dba.perf.myperf.db.DBConnectionWrapper)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 DBGroupInfo (com.yahoo.dba.perf.myperf.common.DBGroupInfo)3 MetricsGroup (com.yahoo.dba.perf.myperf.common.MetricsGroup)3 HashSet (java.util.HashSet)3 ConfigBlock (com.yahoo.dba.perf.myperf.common.ConfigBlock)2 Metric (com.yahoo.dba.perf.myperf.common.Metric)2