use of com.alibaba.cobar.manager.dao.CobarAdapterDAO 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;
}
use of com.alibaba.cobar.manager.dao.CobarAdapterDAO 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;
}
use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.
the class CobarNodeInstantPerfValueAjax method listThreadPool.
/**
* ThreadPool Tab
*
* @param params
* @return
*/
private List<Map<String, Object>> listThreadPool(AjaxParams params) {
CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
if (!perfAccesser.checkConnection()) {
return null;
}
List<ThreadPoolStatus> pools = perfAccesser.listThreadPoolStatus();
List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
for (ThreadPoolStatus t : pools) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("threadPoolName", t.getThreadPoolName());
map.put("poolSize", t.getPoolSize());
map.put("activeSize", t.getActiveSize());
map.put("taskQueue", t.getTaskQueue());
map.put("completedTask", FormatUtil.formatNumber(t.getCompletedTask()));
map.put("totalTask", FormatUtil.formatNumber(t.getTotalTask()));
returnList.add(map);
}
return returnList;
}
use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.
the class CobarNodeInstantPerfValueAjax method listCommand.
/**
* Command Tab
*
* @param params
* @return
*/
private List<Map<String, Object>> listCommand(AjaxParams params) {
CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
if (!perfAccesser.checkConnection()) {
return null;
}
List<CommandStatus> list = perfAccesser.listCommandStatus();
List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
// the last element is total count
long[] a = new long[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
for (CommandStatus l : list) {
a[0] += l.getQuery();
a[1] += l.getStmtPrepared();
a[2] += l.getStmtExecute();
a[3] += l.getStmtClose();
a[4] += l.getPing();
a[5] += l.getQuit();
a[6] += l.getOther();
a[7] += l.getInitDB();
a[8] += l.getKill();
Map<String, Object> map = new HashMap<String, Object>();
map.put("processorId", l.getProcessorId());
map.put("stmtPrepared", FormatUtil.formatNumber(l.getStmtPrepared()));
map.put("stmtExecute", FormatUtil.formatNumber(l.getStmtExecute()));
map.put("query", FormatUtil.formatNumber(l.getQuery()));
map.put("stmtClose", FormatUtil.formatNumber(l.getStmtClose()));
map.put("ping", FormatUtil.formatNumber(l.getPing()));
map.put("quit", FormatUtil.formatNumber(l.getQuit()));
map.put("other", FormatUtil.formatNumber(l.getOther()));
map.put("kill", FormatUtil.formatNumber(l.getKill()));
map.put("initDB", FormatUtil.formatNumber(l.getInitDB()));
returnList.add(map);
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("processorId", "Total");
map.put("stmtPrepared", FormatUtil.formatNumber(a[1]));
map.put("stmtExecute", FormatUtil.formatNumber(a[2]));
map.put("query", FormatUtil.formatNumber(a[0]));
map.put("stmtClose", FormatUtil.formatNumber(a[3]));
map.put("ping", FormatUtil.formatNumber(a[4]));
map.put("quit", FormatUtil.formatNumber(a[5]));
map.put("other", FormatUtil.formatNumber(a[6]));
map.put("kill", FormatUtil.formatNumber(a[8]));
map.put("initDB", FormatUtil.formatNumber(a[7]));
returnList.add(map);
return returnList;
}
use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.
the class ConnectionControlScreen method handleRequestInternal.
@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);
}
String cobarNodeId = request.getParameter("cobarNodeId");
long cobarId = -1;
if (null != cobarNodeId) {
cobarId = Long.parseLong(cobarNodeId);
}
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, ConstantDefine.ACTIVE);
} else {
cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
}
}
List<Map<String, Object>> cobarViewList = null;
if (null != cobarList && cobarList.size() > 0) {
ListSortUtil.sortCobarByName(cobarList);
cobarViewList = new ArrayList<Map<String, Object>>();
for (CobarDO c : cobarList) {
CobarAdapterDAO perf = cobarAccesser.getAccesser(c.getId());
if (perf.checkConnection()) {
Map<String, Object> cobarMap = new HashMap<String, Object>();
cobarMap.put("id", c.getId());
cobarMap.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
cobarViewList.add(cobarMap);
}
}
}
/* cobarId=-2, cobar InActive; cobarId=-3, connection error */
List<ConnectionStatus> connecList = null;
if (cobarId > 0) {
CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(cobarId);
if (cobar.getStatus().equals(ConstantDefine.ACTIVE)) {
CobarAdapterDAO perf = cobarAccesser.getAccesser(cobarId);
if (!perf.checkConnection()) {
cobarId = -3;
} else {
connecList = perf.listConnectionStatus();
}
} else {
cobarId = -2;
}
}
List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
if (null != connecList) {
ListSortUtil.sortConnections(connecList);
for (ConnectionStatus c : connecList) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("processor", c.getProcessor());
map.put("id", c.getId());
map.put("host", c.getHost());
map.put("port", c.getPort());
map.put("local_port", c.getLocal_port());
map.put("schema", c.getSchema());
map.put("charset", c.getCharset());
map.put("netIn", FormatUtil.formatStore(c.getNetIn()));
map.put("netOut", FormatUtil.formatStore(c.getNetOut()));
map.put("aliveTime", FormatUtil.formatTime(c.getAliveTime() * 1000, 2));
map.put("attempsCount", FormatUtil.formatNumber(c.getAttempsCount()));
map.put("recvBuffer", FormatUtil.formatStore(c.getRecvBuffer()));
map.put("sendQueue", c.getSendQueue());
map.put("channel", c.getChannel());
returnList.add(map);
}
}
return new ModelAndView("c_connection", new FluenceHashMap<String, Object>().putKeyValue("cList", clusterList).putKeyValue("cobarList", cobarViewList).putKeyValue("clusterId", clusterId).putKeyValue("cobarId", cobarId).putKeyValue("connecList", returnList).putKeyValue("user", user));
}
Aggregations