Authored by linlong

update

package com.monitor.middleware.memcached.ctrl;
import com.model.MObjectInfo;
import com.model.TypeInfo;
import com.monitor.cmdb.service.IMObjectInfoService;
import com.monitor.cmdb.service.ITypeInfoService;
import com.monitor.common.util.SpringContextUtils;
... ... @@ -11,6 +13,7 @@ import com.monitor.zabbix.enums.NetIfEnum;
import com.monitor.zabbix.enums.SystemCpuEnum;
import com.monitor.zabbix.enums.VmMemoryEnum;
import com.monitor.zabbix.service.ZabbixTaskService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -20,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* Created by yoho on 2016/9/21.
... ... @@ -37,6 +41,8 @@ public class MemcachedCtrl {
private static final String QCLOUD_JAVA_L2 = "qcloud_java_l2";
@Autowired
private ITypeInfoService typeService;
@Autowired
IMObjectInfoService imObjectInfoService;
... ... @@ -59,50 +65,69 @@ public class MemcachedCtrl {
}
}
List<MemcachedVo> aws1 = new ArrayList<>();
List<MemcachedVo> aws2 = new ArrayList<>();
List<MemcachedVo> qcloud1 = new ArrayList<>();
List<MemcachedVo> qcloud2 = new ArrayList<>();
for (MemcachedVo vo : memList) {
if (vo.getName().startsWith(AWS_JAVA_L1)) {
aws1.add(vo);
} else if (vo.getName().startsWith(AWS_JAVA_L2)) {
aws2.add(vo);
} else if (vo.getName().startsWith(QCLOUD_JAVA_L1)) {
qcloud1.add(vo);
} else {
qcloud2.add(vo);
List<String> memcachedSort = getMemcachedSort();
Map<String, List<MemcachedVo>> map = new LinkedHashMap<>();
for (int i = 0; i < memcachedSort.size(); i++) {
List<MemcachedVo> temp = new ArrayList<>();
for (MemcachedVo vo : memList) {
if (vo.getName().startsWith(memcachedSort.get(i))) {
temp.add(vo);
}
}
map.put(memcachedSort.get(i), temp);
}
Collections.sort(aws1, new URLComparator());
Collections.sort(aws2, new URLComparator());
Collections.sort(qcloud1, new URLComparator());
Collections.sort(qcloud2, new URLComparator());
List<MemcachedVo> result = new ArrayList<>();
if (!CollectionUtils.isEmpty(aws1)) {
result.add(mergeMemcacheVo(aws1, AWS_JAVA_L1));
}
if (!CollectionUtils.isEmpty(aws2)) {
result.add(mergeMemcacheVo(aws2, AWS_JAVA_L2));
}
if (!CollectionUtils.isEmpty(qcloud1)) {
result.add(mergeMemcacheVo(qcloud1, QCLOUD_JAVA_L1));
}
if (!CollectionUtils.isEmpty(qcloud2)) {
result.add(mergeMemcacheVo(qcloud2, QCLOUD_JAVA_L2));
for (Map.Entry<String, List<MemcachedVo>> entry : map.entrySet()) {
String sortName = entry.getKey();
List<MemcachedVo> list = entry.getValue();
if(!CollectionUtils.isEmpty(list)){
Collections.sort(list, new URLComparator());
result.add(mergeMemcacheVo(list, sortName));
}
}
response.setData(result);
return response;
}
/**
* 获取所有memcached的种类
* @return
*/
private List<String> getMemcachedSort() {
Map<String, List<MObjectInfo>> serversMap = new HashMap<>();
List<TypeInfo> typeList = typeService.queryAllTypesInfo();
TypeInfo parentTypeInfo = null;
for (TypeInfo typeInfo : typeList) {
if (StringUtils.equals("memcached", typeInfo.getTypeName()) && 0 == typeInfo.getTypeIsLeaf()) {
parentTypeInfo = typeInfo;
break;
}
}
List<TypeInfo> childTypeList = typeService.queryChildTypesInfo(parentTypeInfo.getTypeId());
List<String> sorts = new ArrayList<>();
if (!CollectionUtils.isEmpty(childTypeList)) {
for (int i = 0; i < childTypeList.size(); i++) {
sorts.add(childTypeList.get(i).getTypeName());
}
}
return sorts;
}
/**
* 合并同类的memcached
*
* @param list
*/
/**
* 合并同类的memcached
*
* @param list
*/
private MemcachedVo mergeMemcacheVo(List<MemcachedVo> list, String name) {
MemcachedVo temp = list.get(0);
temp.setName(name);
... ... @@ -117,9 +142,9 @@ public class MemcachedCtrl {
temp.setCmdGet(temp.getCmdGet() + "\r\n" + vo.getCmdGet());
temp.setCmdSet(temp.getCmdSet() + "\r\n" + vo.getCmdSet());
temp.setCurConnections(temp.getCurConnections() + "\r\n" + vo.getCurConnections());
temp.setCpu(temp.getCpu()+"\r\n"+vo.getCpu());
temp.setMem(temp.getMem()+"\r\n"+vo.getMem());
temp.setNet(temp.getNet()+"\r\n"+vo.getNet());
temp.setCpu(temp.getCpu() + "\r\n" + vo.getCpu());
temp.setMem(temp.getMem() + "\r\n" + vo.getMem());
temp.setNet(temp.getNet() + "\r\n" + vo.getNet());
}
return temp;
}
... ...