Search in sources :

Example 1 with ResultList

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

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

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

the class ReplLagQueryProcessor 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_repl_slave");
    ResultList rList = null;
    rList = context.getQueryEngine().executeQueryGeneric(qps2, connWrapper, qps.getMaxRows());
    String master = null;
    String port = null;
    if (rList != null) {
        java.util.LinkedHashMap<String, String> kvPairs = new java.util.LinkedHashMap<String, String>(rList.getRows().size());
        for (ResultRow row : rList.getRows()) {
            if (row.getColumns() == null || row.getColumns().size() < 2)
                continue;
            kvPairs.put(row.getColumns().get(0), row.getColumns().get(1));
        }
        master = kvPairs.get("Master_Host");
        port = kvPairs.get("Master_Port");
        if (master != null && !master.isEmpty() && port != null && !port.isEmpty()) {
            logger.info("Query master status from (" + master + ":" + port + ")");
            DBInstanceInfo dbinfo2 = new DBInstanceInfo();
            dbinfo2.setHostName(master);
            dbinfo2.setPort(port);
            dbinfo2.setDatabaseName("information_schema");
            dbinfo2.setDbType("mysql");
            String url = dbinfo2.getConnectionString();
            DBCredential cred = null;
            if (appUser != null) {
                try {
                    //first, check if the user has his own credential
                    cred = context.getMetaDb().retrieveDBCredential(appUser, dbinfo.getDbGroupName());
                    if (cred != null) {
                        Connection conn = null;
                        Statement stmt = null;
                        ResultSet rs = null;
                        try {
                            DriverManager.setLoginTimeout(60);
                            conn = DriverManager.getConnection(url, cred.getUsername(), cred.getPassword());
                            if (conn != null) {
                                stmt = conn.createStatement();
                                rs = stmt.executeQuery("show master status");
                                //TODO rearrange order
                                ResultList rList2 = new ResultList();
                                rList2.setColumnDescriptor(rList.getColumnDescriptor());
                                for (String e : SLAVE_LAG_ENTRIES) {
                                    ResultRow row = new ResultRow();
                                    row.setColumnDescriptor(rList.getColumnDescriptor());
                                    row.addColumn(e);
                                    row.addColumn(kvPairs.get(e));
                                    rList2.addRow(row);
                                    kvPairs.remove(e);
                                }
                                while (rs != null && rs.next()) {
                                    ResultRow row = new ResultRow();
                                    row.setColumnDescriptor(rList.getColumnDescriptor());
                                    row.addColumn("Master: File");
                                    row.addColumn(rs.getString("File"));
                                    rList2.addRow(row);
                                    row = new ResultRow();
                                    row.setColumnDescriptor(rList.getColumnDescriptor());
                                    row.addColumn("Master: Position");
                                    row.addColumn(rs.getString("Position"));
                                    rList2.addRow(row);
                                //TODO gtid set
                                }
                                //now add slave position info
                                for (String e : SLAVE_POS_ENTRIES) {
                                    ResultRow row = new ResultRow();
                                    row.setColumnDescriptor(rList.getColumnDescriptor());
                                    row.addColumn(e);
                                    row.addColumn(kvPairs.get(e));
                                    rList2.addRow(row);
                                    kvPairs.remove(e);
                                }
                                //now add remaining entries
                                for (Map.Entry<String, String> e : kvPairs.entrySet()) {
                                    ResultRow row = new ResultRow();
                                    row.setColumnDescriptor(rList.getColumnDescriptor());
                                    row.addColumn(e.getKey());
                                    row.addColumn(e.getValue());
                                    rList2.addRow(row);
                                }
                                return rList2;
                            }
                        } catch (Exception ex) {
                        } finally {
                            DBUtils.close(rs);
                            DBUtils.close(stmt);
                            DBUtils.close(conn);
                        }
                    }
                } catch (Exception ex) {
                }
            }
        }
    }
    return rList;
}
Also used : ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) Statement(java.sql.Statement) Connection(java.sql.Connection) QueryParameters(com.yahoo.dba.perf.myperf.common.QueryParameters) DBCredential(com.yahoo.dba.perf.myperf.common.DBCredential) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Map(java.util.Map) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo)

Example 4 with ResultList

use of com.yahoo.dba.perf.myperf.common.ResultList 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 5 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, Metric[] metrics, boolean hasKeyColumn, int dbid, long startDate, long endDate, boolean agg) {
    String[] ms = new String[metrics.length];
    for (int i = 0; i < metrics.length; i++) ms[i] = metrics[i].getName();
    if (!agg)
        return retrieveMetrics(metricGroupName, ms, hasKeyColumn, dbid, startDate, 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();
    //build select list
    StringBuilder grpBy = new StringBuilder();
    sb.append("SNAP_ID");
    sb.append(", TS");
    for (Metric me : metrics) {
        if (me.isIncremental())
            sb.append(", sum(");
        else
            sb.append(", avg(");
        sb.append(me.getName()).append(") ").append(me.getName());
    }
    String sql = "select " + sb.toString() + " from " + metricGroupName + " where dbid=? and snap_id between ? and ? group by snap_id, ts order by 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) Metric(com.yahoo.dba.perf.myperf.common.Metric) 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