Search in sources :

Example 6 with ColumnDescriptor

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

the class VarhistoryController 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;
    //first session check
    boolean isSessionValid = WebAppUtil.hasValidSession(req);
    if (!isSessionValid)
        return this.respondFailure("session timeout. Please logout and re-login.", req);
    qps = WebAppUtil.parseRequestParameter(req);
    qps.setSql("mysql_global_variables");
    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);
    //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 = new ResultList();
    ColumnDescriptor desc = new ColumnDescriptor();
    desc.addColumn("VARIABLE_NAME", false, 1);
    desc.addColumn("VARIABLE_VALUE", false, 2);
    desc.addColumn("COMMENTS", false, 3);
    rList.setColumnDescriptor(desc);
    try {
        ConfigHistory ch = ConfigHistory.load(new File(new File(this.frameworkContext.getFileReposirtoryPath()), "autoscan"), dbinfo);
        if (ch != null && ch.getChanges().size() > 0) {
            {
                ResultRow row = new ResultRow();
                List<String> cols = new ArrayList<String>();
                cols.add("CHANGES");
                cols.add("");
                cols.add(ch.getStartingConfig().getTime() + " - " + ch.getLastCheckedConfig().getTime());
                row.setColumns(cols);
                row.setColumnDescriptor(desc);
                rList.addRow(row);
            }
            //list changed in reverse order
            for (int i = ch.getChanges().size() - 1; i >= 0; i--) {
                ConfigBlock cb = ch.getChanges().get(i);
                ResultRow row = new ResultRow();
                List<String> cols = new ArrayList<String>();
                cols.add("CHANGE TIME");
                cols.add(cb.getTime());
                cols.add("Timestamp (UTC) when checked");
                row.setColumns(cols);
                row.setColumnDescriptor(desc);
                rList.addRow(row);
                HashMap<String, String> changes = new HashMap<String, String>();
                //scan changes with old value
                for (Map.Entry<String, String> e : cb.getVariables().entrySet()) {
                    String key = e.getKey();
                    String val = e.getValue();
                    if (key.startsWith("+-")) {
                        changes.put(key.substring(2), val);
                    }
                }
                for (Map.Entry<String, String> e : cb.getVariables().entrySet()) {
                    String key = e.getKey();
                    String v = e.getValue();
                    row = new ResultRow();
                    cols = new ArrayList<String>();
                    if (key.startsWith("+-"))
                        //skip
                        continue;
                    else if (key.startsWith("+-"))
                        //removed
                        cols.add(key.substring(1));
                    else
                        cols.add(key);
                    cols.add(v);
                    if (changes.containsKey(key))
                        cols.add("Prev Value: " + changes.get(key));
                    else if (key.startsWith("-"))
                        cols.add("Removed");
                    else
                        cols.add("");
                    row.setColumns(cols);
                    row.setColumnDescriptor(desc);
                    rList.addRow(row);
                }
                //add an empty line
                row = new ResultRow();
                cols = new ArrayList<String>();
                cols.add("");
                cols.add("");
                cols.add("");
                row.setColumns(cols);
                row.setColumnDescriptor(desc);
                rList.addRow(row);
            }
        }
        if (ch != null) {
            ConfigBlock cb = ch.getStartingConfig();
            ResultRow row = new ResultRow();
            List<String> cols = new ArrayList<String>();
            cols.add("FIRST RECORD TIME");
            cols.add(cb.getTime());
            if (ch != null && ch.getChanges().size() > 0)
                cols.add("First Recorded Timestamp (UTC)");
            else
                cols.add("No Changes Since First Check (Timestamp UTC)");
            row.setColumns(cols);
            row.setColumnDescriptor(desc);
            rList.addRow(row);
            for (Map.Entry<String, String> e : cb.getVariables().entrySet()) {
                String key = e.getKey();
                String v = e.getValue();
                row = new ResultRow();
                cols = new ArrayList<String>();
                cols.add(key);
                cols.add(v);
                cols.add("");
                row.setColumns(cols);
                row.setColumnDescriptor(desc);
                rList.addRow(row);
            }
        } else {
            status = Constants.STATUS_BAD;
            message = "No variable configuration history has been recorded yet.";
        }
    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Exception", ex);
        status = Constants.STATUS_BAD;
        message = "Exception: " + ex.getMessage();
    }
    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(rList, qps, status, message));
    return mv;
}
Also used : ResultRow(com.yahoo.dba.perf.myperf.common.ResultRow) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) 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) ConfigHistory(com.yahoo.dba.perf.myperf.common.ConfigHistory) ConfigBlock(com.yahoo.dba.perf.myperf.common.ConfigBlock) ArrayList(java.util.ArrayList) List(java.util.List) ResultList(com.yahoo.dba.perf.myperf.common.ResultList) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) DBInstanceInfo(com.yahoo.dba.perf.myperf.common.DBInstanceInfo)

Example 7 with ColumnDescriptor

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

the class InnoController method buildSemapList.

private ResultList buildSemapList(List<SemaphoreEntry> semapList) {
    ResultList rList = new ResultList();
    ColumnDescriptor desc = new ColumnDescriptor();
    int idx = 1;
    desc.addColumn("THREAD_ID", false, idx++);
    desc.addColumn("LOCK_TYPE", false, idx++);
    desc.addColumn("LOCK_NAME", false, idx++);
    desc.addColumn("MODE", false, idx++);
    desc.addColumn("LOCATION", false, idx++);
    desc.addColumn("TIME_SEC", false, idx++);
    desc.addColumn("HOLDER", false, idx++);
    desc.addColumn("HODL_MODE", false, idx++);
    desc.addColumn("WAITED_AT", false, idx++);
    rList.setColumnDescriptor(desc);
    for (SemaphoreEntry tx : semapList) {
        if (tx.thread_id == null)
            continue;
        ResultRow row = new ResultRow();
        rList.addRow(row);
        row.setColumnDescriptor(desc);
        List<String> cols = new ArrayList<String>(16);
        row.setColumns(cols);
        cols.add(tx.thread_id);
        cols.add(tx.lock_type);
        cols.add(tx.lock_name);
        cols.add(tx.request_mode);
        cols.add(tx.lock_loc);
        cols.add(tx.waited_time);
        cols.add(tx.lock_holder);
        cols.add(tx.hold_mode);
        cols.add(tx.waited_at);
    }
    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) ArrayList(java.util.ArrayList)

Example 8 with ColumnDescriptor

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

the class InnoController method buildDeadlockList.

private static ResultList buildDeadlockList(List<String> infoList) {
    ResultList rList = new ResultList();
    ColumnDescriptor desc = new ColumnDescriptor();
    int idx = 1;
    desc.addColumn("INFO", false, idx++);
    //TODO lock strcuts
    rList.setColumnDescriptor(desc);
    for (String tx : infoList) {
        ResultRow row = new ResultRow();
        rList.addRow(row);
        row.setColumnDescriptor(desc);
        List<String> cols = new ArrayList<String>(1);
        row.setColumns(cols);
        cols.add(tx);
    }
    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) ArrayList(java.util.ArrayList)

Example 9 with ColumnDescriptor

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

the class InnoController method createHeader.

private ResultList createHeader(Map<String, String> valMap) {
    ResultList rList = new ResultList();
    ColumnDescriptor desc = new ColumnDescriptor();
    desc.addColumn("NAME", false, 1);
    desc.addColumn("VALUE", false, 2);
    rList.setColumnDescriptor(desc);
    for (Map.Entry<String, String> e : valMap.entrySet()) {
        ResultRow row = new ResultRow();
        List<String> vals = new ArrayList<String>(2);
        vals.add(e.getKey());
        vals.add(e.getValue());
        row.setColumnDescriptor(desc);
        row.setColumns(vals);
        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) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 10 with ColumnDescriptor

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

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