Search in sources :

Example 1 with ProcessorStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus in project cobar by alibaba.

the class ClusterInstantPerfValueAjax method getClusterInfo.

private AjaxResult getClusterInfo(AjaxParams params) {
    JSONArray array = params.getArray();
    long clusterId = params.getClusterId();
    JSONObject json = null;
    if (array.size() > 0) {
        json = array.getJSONObject(0);
    }
    AjaxResult rs = new AjaxResult();
    rs.setId(clusterId);
    List<CobarDO> nodes = xmlAccesser.getCobarDAO().getCobarList(clusterId);
    rs.setTotal(nodes.size());
    for (CobarDO cobar : nodes) {
        if (ConstantDefine.IN_ACTIVE.equals(cobar.getStatus())) {
            continue;
        }
        CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(cobar.getId());
        if (!perfAccesser.checkConnection()) {
            rs.addError(1);
            StringBuilder sb = new StringBuilder("getClusterInfo : cobar connect error for [ Name:");
            sb.append(cobar.getName()).append(" Host:").append(cobar.getHost()).append(" ]");
            logger.error(sb.toString());
            continue;
        }
        rs.addActive(1);
        rs.setSchema(perfAccesser.listDataBases().size());
        List<ProcessorStatus> list = perfAccesser.listProccessorStatus();
        rs.addNetIn(groupByPList(list, NET_IN));
        rs.addNetOut(groupByPList(list, NET_OUT));
        rs.addConnection(groupByPList(list, CONNECTION));
        rs.setTimestamp(list.get(list.size() - 1).getSampleTimeStamp());
        List<CommandStatus> commandList = perfAccesser.listCommandStatus();
        rs.addRequest(groupByCList(commandList, REQUEST_COUNT));
    }
    if (json != null && json.getLong("netIn") != -1) {
        long o_tiemstamp = json.getLong("timestamp");
        rs.setNetIn_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(rs.getNetIn(), json.getLong("netIn"), rs.getTimestamp(), o_tiemstamp, 1000.0))));
        rs.setNetOut_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(rs.getNetOut(), json.getLong("netOut"), rs.getTimestamp(), o_tiemstamp, 1000.0))));
        rs.setRequest_deriv(FormatUtil.formatNumber(Math.round(MathUtil.getDerivate(rs.getRequest(), json.getLong("reCount"), rs.getTimestamp(), o_tiemstamp, 1000.0))));
    }
    return rs;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) CommandStatus(com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ProcessorStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)

Example 2 with ProcessorStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus in project cobar by alibaba.

the class ClusterInstantPerfValueAjax method getClusterThroughput.

@SuppressWarnings("unchecked")
private List<Map<String, Object>> getClusterThroughput(AjaxParams params) {
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    JSONArray array = params.getArray();
    JSONObject json = null;
    Map<Long, JSONObject> cobarRequest = new HashMap<Long, JSONObject>();
    for (int i = 0; i < array.size(); i++) {
        JSONObject js = array.getJSONObject(i);
        if ("cluster".equals(js.getString("flag"))) {
            json = js;
        } else if ("cobar".equals(js.getString("flag"))) {
            cobarRequest.put(js.getLong("id"), js);
        }
    }
    PropertyUtilsBean util = new PropertyUtilsBean();
    long clusterId = params.getClusterId();
    List<CobarDO> nodes = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
    AjaxResult cluster = new AjaxResult();
    cluster.setId(clusterId);
    cluster.setFlag("cluster");
    long timestamp = 0;
    for (CobarDO node : nodes) {
        CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(node.getId());
        if (!perfAccesser.checkConnection()) {
            StringBuilder sb = new StringBuilder("getClusterThroughput: cobar connect error for Name:");
            sb.append(node.getName()).append(" Host:").append(node.getHost());
            logger.error(sb.toString());
            continue;
        }
        AjaxResult re = new AjaxResult();
        List<ProcessorStatus> list = perfAccesser.listProccessorStatus();
        List<CommandStatus> cmdList = perfAccesser.listCommandStatus();
        long cobarNetIn = groupByPList(list, NET_IN);
        long cobarNetOut = groupByPList(list, NET_OUT);
        long cobarRequestCount = groupByCList(cmdList, REQUEST_COUNT);
        cluster.addRequest(cobarRequestCount);
        cluster.addNetIn(cobarNetIn);
        cluster.addNetOut(cobarNetOut);
        re.setId(node.getId());
        re.setFlag("cobar");
        re.setNetIn(cobarNetIn);
        re.setNetOut(cobarNetOut);
        re.setConnection(groupByPList(list, CONNECTION));
        re.setRequest(cobarRequestCount);
        timestamp = list.get(list.size() - 1).getSampleTimeStamp();
        re.setTimestamp(timestamp);
        JSONObject jsonTmp = cobarRequest.get(node.getId());
        if (jsonTmp != null) {
            re.setNetIn_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(cobarNetIn, jsonTmp.getLong("netIn"), timestamp, jsonTmp.getLong("timestamp"), 1000.0))));
            re.setNetOut_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(cobarNetOut, jsonTmp.getLong("netOut"), timestamp, jsonTmp.getLong("timestamp"), 1000.0))));
            re.setRequest_deriv(FormatUtil.formatNumber(Math.round(MathUtil.getDerivate(cobarRequestCount, jsonTmp.getLong("reCount"), timestamp, jsonTmp.getLong("timestamp"), 1000.0))));
        }
        Map<String, Object> map = null;
        try {
            map = util.describe(re);
        } catch (Exception e) {
            logger.error(e);
            throw new RuntimeException(e);
        }
        if (null != map) {
            result.add(map);
        }
    }
    cluster.setTimestamp(timestamp);
    if (null != json && json.getLong("netIn") != -1) {
        long o_tiemstamp = json.getLong("timestamp");
        cluster.setNetIn_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(cluster.getNetIn(), json.getLong("netIn"), timestamp, o_tiemstamp, 1000.0))));
        cluster.setNetOut_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(cluster.getNetOut(), json.getLong("netOut"), timestamp, o_tiemstamp, 1000.0))));
        cluster.setRequest_deriv(FormatUtil.formatNumber(Math.round(MathUtil.getDerivate(cluster.getRequest(), json.getLong("reCount"), timestamp, o_tiemstamp, 1000.0))));
    }
    Map<String, Object> m = null;
    try {
        m = util.describe(cluster);
    } catch (Exception e) {
        logger.error(e);
        throw new RuntimeException(e);
    }
    if (null != m) {
        result.add(m);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) ArrayList(java.util.ArrayList) CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) JSONArray(net.sf.json.JSONArray) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ProcessorStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JSONObject(net.sf.json.JSONObject) JSONObject(net.sf.json.JSONObject) CommandStatus(com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ProcessorStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus in project cobar by alibaba.

the class CobarNodeInstantPerfValueAjax method listProcessorStatus.

/**
     * Processor Tab
     * 
     * @param params
     * @return
     */
private List<Map<String, Object>> listProcessorStatus(AjaxParams params) {
    long timestamp = 0;
    CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
    if (!perfAccesser.checkConnection()) {
        return null;
    }
    List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
    List<ProcessorStatus> list = perfAccesser.listProccessorStatus();
    long[] a = new long[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    for (ProcessorStatus e : list) {
        a[0] += e.getNetIn();
        a[1] += e.getNetOut();
        a[2] += e.getRequestCount();
        a[3] += e.getrQueue();
        a[4] += e.getwQueue();
        a[5] += e.getFreeBuffer();
        a[6] += e.getTotalBuffer();
        a[7] += e.getConnections();
        a[8] += e.getBc_count();
        timestamp = e.getSampleTimeStamp();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("processorId", e.getProcessorId());
        map.put("netIn", FormatUtil.formatStore(e.getNetIn()));
        map.put("netOut", FormatUtil.formatStore(e.getNetOut()));
        map.put("requestCount", FormatUtil.formatNumber(e.getRequestCount()));
        map.put("rQueue", e.getrQueue());
        map.put("wQueue", e.getwQueue());
        map.put("freeBuffer", e.getFreeBuffer());
        map.put("totalBuffer", e.getTotalBuffer());
        map.put("connections", e.getConnections());
        map.put("bc_count", e.getBc_count());
        returnList.add(map);
    }
    Map<String, Object> total = new HashMap<String, Object>();
    total.put("processorId", "TOTAL");
    total.put("netIn", FormatUtil.formatStore(a[0]));
    total.put("netOut", FormatUtil.formatStore(a[1]));
    total.put("requestCount", FormatUtil.formatNumber(a[2]));
    total.put("rQueue", a[3]);
    total.put("wQueue", a[4]);
    total.put("freeBuffer", a[5]);
    total.put("totalBuffer", a[6]);
    total.put("connections", a[7]);
    total.put("bc_count", a[8]);
    total.put("sampleTimeStamp", timestamp);
    total.put("netInC", a[0]);
    total.put("netOutC", a[1]);
    total.put("requestCountC", a[2]);
    returnList.add(total);
    return returnList;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) ProcessorStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)

Example 4 with ProcessorStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus in project cobar by alibaba.

the class CobarNodeInstantPerfValueAjax method getServerStatus.

private Map<String, Object> getServerStatus(AjaxParams params) {
    JSONArray array = params.getArray();
    JSONObject jobject = array.getJSONObject(0);
    CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
    if (!perfAccesser.checkConnection()) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uptime", 0);
        map.put("usedMemory", 0);
        map.put("maxMemory", 0);
        map.put("totalMemory", 0);
        map.put("connectionCount", 0);
        map.put("status", "ERROR");
        map.put("version", "UNKNOWN");
        map.put("starttime", 0);
        map.put("netInC", 0);
        map.put("netOutC", 0);
        map.put("requestCountC", 0);
        map.put("sampleTimeStamp", System.currentTimeMillis());
        map.put("netIn_deriv", 0);
        map.put("netOut_deriv", 0);
        map.put("reCount_deriv", 0);
        return map;
    }
    ServerStatus ss = perfAccesser.getServerStatus();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("uptime", ss.getUptime());
    map.put("usedMemory", FormatUtil.formatStore(ss.getUsedMemory()));
    map.put("maxMemory", FormatUtil.formatStore(ss.getMaxMemory()));
    map.put("totalMemory", FormatUtil.formatStore(ss.getTotalMemory()));
    List<ProcessorStatus> list = perfAccesser.listProccessorStatus();
    List<CommandStatus> cmdList = perfAccesser.listCommandStatus();
    long netIn = groupBy(list, NET_IN);
    long netOut = groupBy(list, NET_OUT);
    long requestCount = groupByCList(cmdList, REQUEST_COUNT);
    long connectionCount = groupBy(list, CONNECTION);
    long timestamp = list.get(list.size() - 1).getSampleTimeStamp();
    long o_netIn = jobject.getLong("netIn");
    long o_netOut = jobject.getLong("netOut");
    long o_requestCount = jobject.getLong("requestCount");
    long o_timestamp = jobject.getLong("sampleTimeStamp");
    map.put("netInC", netIn);
    map.put("netOutC", netOut);
    map.put("requestCountC", requestCount);
    map.put("sampleTimeStamp", timestamp);
    map.put("netIn_deriv", FormatUtil.formatNetwork((long) MathUtil.getDerivate(netIn, o_netIn, timestamp, o_timestamp, 1000.0)));
    map.put("netOut_deriv", FormatUtil.formatNetwork((long) MathUtil.getDerivate(netOut, o_netOut, timestamp, o_timestamp, 1000.0)));
    map.put("reCount_deriv", FormatUtil.formatNumber((long) MathUtil.getDerivate(requestCount, o_requestCount, timestamp, o_timestamp, 1000.0)));
    map.put("version", FormatUtil.formatVersion(perfAccesser.getVersion()));
    map.put("starttime", perfAccesser.getStartUpTime().getFormatTime());
    map.put("connectionCount", connectionCount);
    map.put("status", ss.getStatus());
    return map;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) JSONArray(net.sf.json.JSONArray) ProcessorStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus) JSONObject(net.sf.json.JSONObject) ServerStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus) JSONObject(net.sf.json.JSONObject) CommandStatus(com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)

Example 5 with ProcessorStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus in project cobar by alibaba.

the class TestProcessor method testListProcessorStatus.

@Test(timeout = 60000)
public void testListProcessorStatus() {
    TestUtils.waitForMonment(50000);
    int listNum = 10;
    List<Connection> connList = new ArrayList<Connection>();
    try {
        //create connection
        for (int i = 0; i < listNum; i++) {
            Connection conn = sCobarNode.createDMLConnection("ddl_test");
            connList.add(conn);
        }
        //get connection num from manager
        List<ProcessorStatus> psList = null;
        int connNum = 0;
        psList = cobarAdapter.listProccessorStatus();
        Assert.assertNotNull(psList);
        Assert.assertEquals(psList.size(), 8);
        for (ProcessorStatus ps : psList) {
            connNum += ps.getConnections();
        }
        Assert.assertEquals(connNum, listNum + 1);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail();
    } finally {
        for (Connection conn : connList) {
            Assert.assertTrue(sCobarNode.detoryConnection(conn));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ProcessorStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus) Test(org.junit.Test)

Aggregations

ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)6 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)4 JSONObject (net.sf.json.JSONObject)4 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JSONArray (net.sf.json.JSONArray)3 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)2 Map (java.util.Map)2 ServerStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 ServletException (javax.servlet.ServletException)1 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)1 Test (org.junit.Test)1