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;
}
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;
}
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));
}
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);
}
Aggregations