Search in sources :

Example 6 with ResultRow

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

the class SNMPQueryProcessor method queryNetwork.

private ResultList queryNetwork(SNMPClient client, QueryParameters qps) throws Exception {
    boolean diff = "1".equalsIgnoreCase(qps.getSqlParams().get("p_2"));
    Map<String, List<SNMPTriple>> snmpData = client.getNetIfData(null);
    if (snmpData == null)
        return null;
    ColumnDescriptor desc = new ColumnDescriptor();
    desc.addColumn("NAME", false, 0);
    desc.addColumn("OID", false, 1);
    desc.addColumn("VALUE", false, 2);
    ResultList rList = new ResultList();
    rList.setColumnDescriptor(desc);
    for (Map.Entry<String, List<SNMPTriple>> e : snmpData.entrySet()) {
        String net = e.getKey();
        for (SNMPTriple t : e.getValue()) {
            if (diff) {
                try {
                    BigDecimal bd = new BigDecimal(t.value);
                } catch (Exception ex) {
                    continue;
                }
            }
            ResultRow row = new ResultRow();
            row.addColumn(net + "." + t.name);
            row.addColumn(t.oid);
            row.addColumn(t.value);
            row.setColumnDescriptor(desc);
            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) SNMPTriple(com.yahoo.dba.perf.myperf.snmp.SNMPClient.SNMPTriple) List(java.util.List) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) Map(java.util.Map) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException)

Example 7 with ResultRow

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

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

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

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

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