Search in sources :

Example 1 with ColumnDescriptor

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

the class InnoDbMutexPostProccessor method process.

@Override
public ResultList process(ResultList rs) {
    TreeMap<String, MutexName> mutexMetrics = new TreeMap<String, MutexName>();
    if (rs != null && rs.getRows().size() > 0) {
        int typeIdx = 0;
        int nameIdx = 1;
        int statusIdx = 2;
        List<ColumnInfo> colList = rs.getColumnDescriptor().getColumns();
        for (int i = 0; i < colList.size(); i++) {
            if ("Type".equalsIgnoreCase(colList.get(i).getName()))
                typeIdx = i;
            else if ("Name".equalsIgnoreCase(colList.get(i).getName()))
                nameIdx = i;
            else if ("Status".equalsIgnoreCase(colList.get(i).getName()))
                statusIdx = i;
        }
        for (ResultRow row : rs.getRows()) {
            try {
                List<String> sList = row.getColumns();
                String type = sList.get(typeIdx);
                String name = sList.get(nameIdx);
                String status = sList.get(statusIdx);
                //split status to name value pair
                String[] nv = status.split("=");
                String key = type + "|" + name + "|" + nv[0];
                int val = Integer.parseInt(nv[1]);
                if (!mutexMetrics.containsKey(key)) {
                    mutexMetrics.put(key, new MutexName(type, name, nv[0]));
                }
                mutexMetrics.get(key).val += val;
                mutexMetrics.get(key).count++;
            } catch (Exception ex) {
            }
        }
    }
    //now build new List
    ResultList rlist = new ResultList();
    ColumnDescriptor desc = new ColumnDescriptor();
    desc.addColumn("NAME", false, 0);
    desc.addColumn("VALUE", true, 1);
    desc.addColumn("COUNT", true, 2);
    rlist.setColumnDescriptor(desc);
    for (MutexName m : mutexMetrics.values()) {
        ResultRow row = new ResultRow();
        row.setColumnDescriptor(desc);
        row.addColumn(m.type + "/" + m.name + "/" + m.waitType);
        row.addColumn(String.valueOf(m.val));
        row.addColumn(String.valueOf(m.count));
        rlist.addRow(row);
    }
    return rlist;
}
Also used : ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) ColumnDescriptor(com.yahoo.dba.perf.myperf.common.ColumnDescriptor) ColumnInfo(com.yahoo.dba.perf.myperf.common.ColumnInfo) TreeMap(java.util.TreeMap)

Example 2 with ColumnDescriptor

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

the class MySQLStatusQueryProcessor method querySingle.

@Override
public ResultList querySingle(MyPerfContext context, DBInstanceInfo dbinfo, String appUser, DBConnectionWrapper connWrapper, QueryParameters qps) throws SQLException {
    QueryParameters qps2 = new QueryParameters();
    qps2.setSql("mysql_show_global_status");
    ResultList rList = null;
    rList = context.getQueryEngine().executeQueryGeneric(qps2, connWrapper, qps.getMaxRows());
    if (rList != null) {
        ResultList newList = new ResultList();
        ColumnDescriptor desc = rList.getColumnDescriptor();
        ColumnDescriptor newDesc = new ColumnDescriptor();
        int idx = 0;
        int nameIdx = 0;
        for (ColumnInfo c : desc.getColumns()) {
            if ("VARIABLE_NAME".equalsIgnoreCase(c.getName()))
                nameIdx = idx;
            if ("VALUE".equalsIgnoreCase(c.getName()))
                newDesc.addColumn("VARIABLE_VALUE", c.isNumberType(), idx++);
            else
                newDesc.addColumn(c.getName().toUpperCase(), c.isNumberType(), idx++);
        }
        newList.setColumnDescriptor(newDesc);
        for (ResultRow row : rList.getRows()) {
            ResultRow newRow = new ResultRow();
            newRow.setColumnDescriptor(newDesc);
            int cols = row.getColumns().size();
            for (int i = 0; i < cols; i++) {
                String v = row.getColumns().get(i);
                if (i == nameIdx) {
                    newRow.addColumn(v == null ? null : v.toUpperCase());
                } else
                    newRow.addColumn(v);
            }
            newList.addRow(newRow);
        }
        return newList;
    }
    return null;
}
Also used : ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) ColumnDescriptor(com.yahoo.dba.perf.myperf.common.ColumnDescriptor) ColumnInfo(com.yahoo.dba.perf.myperf.common.ColumnInfo) QueryParameters(com.yahoo.dba.perf.myperf.common.QueryParameters)

Example 3 with ColumnDescriptor

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

the class ReplShowProcessor method querySingle.

@Override
public ResultList querySingle(MyPerfContext context, DBInstanceInfo dbinfo, String appUser, DBConnectionWrapper connWrapper, QueryParameters qps) throws SQLException {
    Map<String, ReplStatus> statusResults = new java.util.LinkedHashMap<String, ReplStatus>();
    DBCredential cred = context.getMetaDb().retrieveDBCredential(appUser, dbinfo.getDbGroupName());
    ReplServer replServer = new ReplServer(dbinfo.getHostName(), dbinfo.getPort());
    //check cache
    ReplServer startingServer = null;
    synchronized (this.topologyCache) {
        ReplTopologyCacheEntry cache = this.topologyCache.get(replServer.toString());
        if (cache != null && cache.createTime + context.getMyperfConfig().getReplTopologyCacheMaxAge() > System.currentTimeMillis())
            startingServer = cache.rootServer;
    }
    if (cred != null) {
        if (startingServer == null) {
            statusResults.put(replServer.toString(), new ReplStatus(dbinfo.getHostName(), dbinfo.getPort()));
            queryDetail(context, cred, statusResults, replServer, 0);
        } else {
            Map<String, ReplServer> allServers = startingServer.getAllServers();
            for (Map.Entry<String, ReplServer> e : allServers.entrySet()) {
                ReplServer s = e.getValue();
                ReplServer rplServer = new ReplServer(s.host, s.port);
                rplServer.probed = true;
                statusResults.put(rplServer.toString(), new ReplStatus(s.host, s.port));
                queryDetail(context, cred, statusResults, rplServer, 0);
            }
        }
    }
    ReplServer rootServer = this.buildReplTree(statusResults);
    if (rootServer == null) {
        logger.warning("Cannot find replication root for " + replServer);
    } else if (startingServer == null) {
        //update cache
        logger.info("Update cache");
        synchronized (this.topologyCache) {
            for (Map.Entry<String, ReplStatus> e : statusResults.entrySet()) {
                ReplTopologyCacheEntry cache = this.topologyCache.get(e.getKey());
                if (cache == null) {
                    cache = new ReplTopologyCacheEntry(rootServer);
                    this.topologyCache.put(e.getKey(), cache);
                } else
                    cache.update(rootServer);
            }
        }
    }
    ResultList rList = new ResultList();
    ColumnDescriptor desc = new ColumnDescriptor();
    rList.setColumnDescriptor(desc);
    int idx = 0;
    //use host:port
    desc.addColumn("SERVER", false, idx++);
    //use host:port
    desc.addColumn("MASTER SERVER", false, idx++);
    desc.addColumn("LAG", false, idx++);
    //IO/SQL
    desc.addColumn("IO/SQL", false, idx++);
    //Master file: master position
    desc.addColumn("MASTER: FILE", false, idx++);
    //Master file: master position
    desc.addColumn("MASTER LOG FILE", false, idx++);
    desc.addColumn("READ MASTER LOG POS", false, idx++);
    desc.addColumn("RELAY MASTER LOG FILE", false, idx++);
    desc.addColumn("EXEC MASTER LOG POS", false, idx++);
    desc.addColumn("MASTER EXECUTED GTID", false, idx++);
    desc.addColumn("EXECUTED GTID", false, idx++);
    Set<String> probed = new HashSet<String>();
    outputTree(rootServer, statusResults, probed, 0, rList);
    //}
    return rList;
}
Also used : ResultList(com.yahoo.dba.perf.myperf.common.ResultList) ColumnDescriptor(com.yahoo.dba.perf.myperf.common.ColumnDescriptor) DBCredential(com.yahoo.dba.perf.myperf.common.DBCredential) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with ColumnDescriptor

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

the class MetricsDbBase method retrieveUDMMetrics.

/** 
	   * Retrieve user defined merics
	   * @param metrics
	   * @param dbid
	   * @param startDate
	   * @param endDate
	   * @return
	   */
public ResultList retrieveUDMMetrics(String metric, int dbid, long startDate, long endDate) {
    int[] snaps = this.getSnapshostRange(startDate, endDate);
    //no data
    if (snaps == null)
        return null;
    //later, connection pooling
    ResultList rList = null;
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    int code = 0;
    if (this.metricCodeMap.containsKey(metric)) {
        code = this.metricCodeMap.get(metric);
    } else {
        logger.warning("Failed to find metrics code for " + metric + ", " + this.metricCodeMap);
        return null;
    }
    String sql = "select SNAP_ID, TS, METRIC_ID, VALUE from METRIC_GENERIC where dbid=? and snap_id between ? and ? and METRIC_ID=? order by dbid, METRIC_ID, snap_id";
    //String sql = "select * from "+metricGroupName+" where dbid=?";
    logger.log(Level.INFO, "To retrieve " + metric + ", " + code + " on db " + dbid + " with time range (" + startDate + ", " + endDate + "), using " + sql);
    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]);
        stmt.setLong(4, code);
        rs = stmt.executeQuery();
        if (rs == null)
            return rList;
        rList = new ResultList();
        //java.sql.ResultSetMetaData meta =  rs.getMetaData();
        ColumnDescriptor desc = new ColumnDescriptor();
        desc.addColumn("SNAP_ID", true, 1);
        desc.addColumn("TS", true, 2);
        desc.addColumn(metric, true, 3);
        rList.setColumnDescriptor(desc);
        int rowCnt = 0;
        //List<ColumnInfo> cols = desc.getColumns();
        while (rs.next()) {
            //logger.info(new java.util.Date()+": process "+rowCnt+" rows");
            ResultRow row = new ResultRow();
            row.setColumnDescriptor(desc);
            java.util.ArrayList<String> cols2 = new java.util.ArrayList<String>(3);
            cols2.add(rs.getString(1));
            cols2.add(rs.getString(2));
            cols2.add(rs.getString(4));
            row.setColumns(cols2);
            rList.addRow(row);
            rowCnt++;
            if (rowCnt >= 5000)
                break;
        }
        logger.info(new java.util.Date() + ": Process results done: " + rList.getRows().size());
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Failed to retrieve UDM " + metric + " for db " + dbid + " with time range (" + startDate + ", " + endDate + ")", ex);
    } finally {
        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) ColumnDescriptor(com.yahoo.dba.perf.myperf.common.ColumnDescriptor) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 5 with ColumnDescriptor

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

the class VardiffController method handleRequestImpl.

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    int status = Constants.STATUS_OK;
    String message = "OK";
    logger.info("receive url " + req.getQueryString());
    QueryParameters qps = null;
    DBInstanceInfo dbinfo = null;
    DBInstanceInfo dbinfo2 = null;
    DBConnectionWrapper connWrapper = null;
    DBConnectionWrapper connWrapper2 = null;
    qps = WebAppUtil.parseRequestParameter(req);
    qps.setSql("mysql_global_variables");
    qps.getSqlParams().put("p_1", "");
    String group2 = req.getParameter("p_1");
    String host2 = req.getParameter("p_2");
    //validation input
    String validation = qps.validate();
    if (validation == null || validation.isEmpty()) {
        //do we have such query?
        try {
            QueryInputValidator.validateSql(this.frameworkContext.getSqlManager(), qps);
        } catch (Exception ex) {
            validation = ex.getMessage();
        }
    }
    if (validation != null && !validation.isEmpty())
        return this.respondFailure(validation, req);
    dbinfo = this.frameworkContext.getDbInfoManager().findDB(qps.getGroup(), qps.getHost());
    if (dbinfo == null)
        return this.respondFailure("Cannot find record for DB (" + qps.getGroup() + ", " + qps.getHost() + ")", req);
    dbinfo2 = this.frameworkContext.getDbInfoManager().findDB(group2, host2);
    if (dbinfo2 == null)
        return this.respondFailure("Cannot find record for DB (" + group2 + ", " + host2 + ")", req);
    try {
        connWrapper = WebAppUtil.getDBConnection(req, this.frameworkContext, dbinfo);
        if (connWrapper == null) {
            status = Constants.STATUS_BAD;
            message = "failed to connect to target db (" + dbinfo + ")";
        } else {
            connWrapper2 = WebAppUtil.getDBConnection(req, this.frameworkContext, dbinfo2);
            if (connWrapper2 == null) {
                status = Constants.STATUS_BAD;
                message = "failed to connect to target db (" + dbinfo2 + ")";
            }
        }
    } catch (Throwable th) {
        logger.log(Level.SEVERE, "Exception", th);
        status = Constants.STATUS_BAD;
        message = "Failed to get connection to target db (" + dbinfo + "): " + th.getMessage();
    }
    if (status == -1)
        return this.respondFailure(message, req);
    //when we reach here, at least we have valid query and can connect to db	
    WebAppUtil.storeLastDbInfoRequest(qps.getGroup(), qps.getHost(), req);
    ModelAndView mv = null;
    ResultList rList = null;
    ResultList rList2 = null;
    try {
        rList = this.frameworkContext.getQueryEngine().executeQueryGeneric(qps, connWrapper, qps.getMaxRows());
        rList2 = this.frameworkContext.getQueryEngine().executeQueryGeneric(qps, connWrapper2, qps.getMaxRows());
        logger.info("Done query " + qps.getSql() + " with " + (rList != null ? rList.getRows().size() : 0) + " records, " + (rList2 != null ? rList2.getRows().size() : 0) + " records");
        WebAppUtil.closeDBConnection(req, connWrapper, false, this.getFrameworkContext().getMyperfConfig().isReuseMonUserConnction());
        WebAppUtil.closeDBConnection(req, connWrapper2, false, this.getFrameworkContext().getMyperfConfig().isReuseMonUserConnction());
    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Exception", ex);
        if (ex instanceof SQLException) {
            SQLException sqlEx = SQLException.class.cast(ex);
            String msg = ex.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);
            if (!DBUtils.checkConnection(connWrapper2.getConnection())) {
                WebAppUtil.closeDBConnection(req, connWrapper2, true, false);
            } else
                WebAppUtil.closeDBConnection(req, connWrapper2, true, false);
        } else {
            WebAppUtil.closeDBConnection(req, connWrapper, false, this.getFrameworkContext().getMyperfConfig().isReuseMonUserConnction());
            WebAppUtil.closeDBConnection(req, connWrapper2, false, this.getFrameworkContext().getMyperfConfig().isReuseMonUserConnction());
        }
        status = Constants.STATUS_BAD;
        message = "Exception: " + ex.getMessage();
    }
    if (status == Constants.STATUS_BAD)
        return this.respondFailure(message, req);
    HashMap<String, String> param1 = new HashMap<String, String>(rList.getRows().size());
    HashMap<String, String> param2 = new HashMap<String, String>(rList2.getRows().size());
    for (ResultRow r : rList.getRows()) {
        param1.put(r.getColumns().get(0).toUpperCase(), r.getColumns().get(1));
    }
    for (ResultRow r : rList2.getRows()) {
        param2.put(r.getColumns().get(0).toUpperCase(), r.getColumns().get(1));
    }
    ColumnDescriptor desc = new ColumnDescriptor();
    desc.addColumn("VARIABLE_NAME", false, 1);
    desc.addColumn("DB1", false, 2);
    desc.addColumn("DB2", false, 3);
    ResultList fList = new ResultList();
    fList.setColumnDescriptor(desc);
    HashSet<String> diffSet = new HashSet<String>();
    for (Map.Entry<String, String> e : param1.entrySet()) {
        String k = e.getKey();
        String v = e.getValue();
        if (v != null)
            v = v.trim();
        else
            v = "";
        String v2 = null;
        if (param2.containsKey(k))
            v2 = param2.get(k);
        if (v2 != null)
            v2 = v2.trim();
        else
            v2 = "";
        if (!v.equals(v2)) {
            ResultRow row = new ResultRow();
            List<String> cols = new ArrayList<String>();
            cols.add(k);
            cols.add(v);
            cols.add(v2);
            row.setColumns(cols);
            row.setColumnDescriptor(desc);
            fList.addRow(row);
            diffSet.add(k);
        }
    }
    for (Map.Entry<String, String> e : param2.entrySet()) {
        String k = e.getKey();
        String v = e.getValue();
        if (v == null || v.isEmpty())
            continue;
        if (diffSet.contains(k) || param1.containsKey(k))
            continue;
        ResultRow row = new ResultRow();
        List<String> cols = new ArrayList<String>();
        cols.add(k);
        cols.add("");
        cols.add(v);
        row.setColumns(cols);
        row.setColumnDescriptor(desc);
        fList.addRow(row);
    }
    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.addObject("json_result", ResultListUtil.toJSONString(fList, qps, status, message));
    return mv;
}
Also used : ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) SQLException(java.sql.SQLException) HashMap(java.util.HashMap) ColumnDescriptor(com.yahoo.dba.perf.myperf.common.ColumnDescriptor) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) QueryParameters(com.yahoo.dba.perf.myperf.common.QueryParameters) SQLException(java.sql.SQLException) DBConnectionWrapper(com.yahoo.dba.perf.myperf.db.DBConnectionWrapper) HashMap(java.util.HashMap) Map(java.util.Map) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo) HashSet(java.util.HashSet)

Aggregations

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