Search in sources :

Example 1 with ServerStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus 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 2 with ServerStatus

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

the class ClusterInstantPerfValueAjax method listCobarMemoryUsage.

private List<Pair<Long, Integer>> listCobarMemoryUsage(AjaxParams params) {
    List<Pair<Long, Integer>> result = new ArrayList<Pair<Long, Integer>>();
    List<CobarDO> nodes = xmlAccesser.getCobarDAO().getCobarList(params.getClusterId(), ConstantDefine.ACTIVE);
    for (CobarDO node : nodes) {
        CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(node.getId());
        if (!perfAccesser.checkConnection()) {
            StringBuilder sb = new StringBuilder("listCobarMemoryUsage: cobar connect error for Name:");
            sb.append(node.getName()).append(" Host:").append(node.getHost());
            logger.error(sb.toString());
            continue;
        }
        ServerStatus ss = perfAccesser.getServerStatus();
        int memoryUsage = 0;
        if (ss.getTotalMemory() != 0)
            memoryUsage = Math.round(ss.getUsedMemory() * 100 / ss.getTotalMemory());
        result.add(new Pair<Long, Integer>(node.getId(), memoryUsage));
    }
    return result;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) ServerStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus) ArrayList(java.util.ArrayList) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) Pair(com.alibaba.cobar.manager.util.Pair)

Example 3 with ServerStatus

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

the class PropertyReloadScreen method handleRequestInternal.

@SuppressWarnings("unchecked")
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    String id = request.getParameter("clusterId");
    long clusterId = -1;
    if (null != id) {
        clusterId = Long.parseLong(id);
    }
    List<ClusterDO> cList = xmlAccesser.getClusterDAO().listAllCluster();
    List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>();
    ListSortUtil.sortClusterByName(cList);
    for (ClusterDO e : cList) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", e.getId());
        map.put("name", CobarStringUtil.htmlEscapedString(e.getName()));
        clusterList.add(map);
    }
    List<CobarDO> cobarList = null;
    if (null != cList && cList.size() > 0) {
        if (-1 == clusterId) {
            clusterId = cList.get(0).getId();
            cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId);
        } else {
            cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId);
        }
    }
    List<Map<String, Object>> cobarListMap = new ArrayList<Map<String, Object>>();
    PropertyUtilsBean util = new PropertyUtilsBean();
    if (null != cobarList) {
        ListSortUtil.sortCobarByName(cobarList);
        for (CobarDO c : cobarList) {
            CobarAdapterDAO perf = cobarAccesser.getAccesser(c.getId());
            Map<String, Object> map;
            try {
                map = util.describe(c);
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
            map.remove("class");
            map.remove("name");
            map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
            if (ConstantDefine.ACTIVE.equals(c.getStatus())) {
                if (!perf.checkConnection()) {
                    map.remove("status");
                    map.put("status", ConstantDefine.ERROR);
                    map.put("reloadTime", "");
                    map.put("rollbackTime", "");
                } else {
                    ServerStatus ss = perf.getServerStatus();
                    String rollbackTime = "NO";
                    String reloadTime = FormatUtil.fromMilliseconds2String(ss.getReloadTime());
                    if (ss.getRollbackTime() != -1) {
                        rollbackTime = FormatUtil.fromMilliseconds2String(ss.getRollbackTime());
                    }
                    map.put("reloadTime", reloadTime);
                    map.put("rollbackTime", rollbackTime);
                }
            } else {
                map.put("reloadTime", "");
                map.put("rollbackTime", "");
            }
            cobarListMap.add(map);
        }
    }
    return new ModelAndView("c_propertyReload", new FluenceHashMap<String, Object>().putKeyValue("cList", clusterList).putKeyValue("cobarList", cobarListMap).putKeyValue("clusterId", clusterId).putKeyValue("user", user));
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) ServerStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) Map(java.util.Map)

Example 4 with ServerStatus

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

the class CobarAccessTest method main.

public static void main(String[] args) throws Exception {
    String xmlpath = "./src/main/resources/";
    CobarAccesser accesser = new CobarAccesser();
    XmlAccesser xmlAccesser = new XmlAccesser();
    XMLFileLoaderPath xmlFileLoader = new XMLFileLoaderPath();
    xmlFileLoader.setXmlPath(xmlpath);
    ClusterDAOImple cluster = new ClusterDAOImple();
    cluster.setXmlFileLoader(xmlFileLoader);
    cluster.afterPropertiesSet();
    CobarDAOImple cobar = new CobarDAOImple();
    cobar.setXmlFileLoader(xmlFileLoader);
    cobar.afterPropertiesSet();
    xmlAccesser.setClusterDAO(cluster);
    xmlAccesser.setCobarDAO(cobar);
    accesser.setXmlAccesser(xmlAccesser);
    AdapterDelegate res = new AdapterDelegate();
    accesser.setCobarAdapterDelegate(res);
    CobarAdapterDAO perf = accesser.getAccesser(1L);
    String version = perf.getVersion();
    System.out.println(version);
    ServerStatus ss = perf.getServerStatus();
    System.out.println(ss.getMaxMemory());
    System.out.println(ss.getStatus());
    System.out.println(ss.getTotalMemory());
    System.out.println(ss.getUptime());
    System.out.println(ss.getUsedMemory());
    System.out.println(ss.getReloadTime());
    System.out.println(ss.getRollbackTime());
    List<String> databases = perf.listDataBases();
    for (String s : databases) {
        System.out.println(s);
    }
//        perf.reloadConfig();
//        perf.rollbackConfig();
//        int num = perf.switchDataNode("circe,cndb,dubbo,napoli", 0);
//        System.out.println("num: " + num);
//        int num = perf.stopHeartbeat("circe,cndb,dubbo,napoli", -10);
//        System.out.println("num: " + num);
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) ClusterDAOImple(com.alibaba.cobar.manager.dao.xml.ClusterDAOImple) XmlAccesser(com.alibaba.cobar.manager.service.XmlAccesser) ServerStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus) XMLFileLoaderPath(com.alibaba.cobar.manager.dao.xml.XMLFileLoaderPath) CobarDAOImple(com.alibaba.cobar.manager.dao.xml.CobarDAOImple) CobarAccesser(com.alibaba.cobar.manager.service.CobarAccesser) AdapterDelegate(com.alibaba.cobar.manager.dao.delegate.AdapterDelegate)

Aggregations

CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)4 ServerStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus)4 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AdapterDelegate (com.alibaba.cobar.manager.dao.delegate.AdapterDelegate)1 ClusterDAOImple (com.alibaba.cobar.manager.dao.xml.ClusterDAOImple)1 CobarDAOImple (com.alibaba.cobar.manager.dao.xml.CobarDAOImple)1 XMLFileLoaderPath (com.alibaba.cobar.manager.dao.xml.XMLFileLoaderPath)1 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)1 ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)1 ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)1 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)1 CobarAccesser (com.alibaba.cobar.manager.service.CobarAccesser)1 XmlAccesser (com.alibaba.cobar.manager.service.XmlAccesser)1 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)1 Pair (com.alibaba.cobar.manager.util.Pair)1 Map (java.util.Map)1 JSONArray (net.sf.json.JSONArray)1 JSONObject (net.sf.json.JSONObject)1