Authored by linlong

update

... ... @@ -8,7 +8,6 @@ import com.monitor.middleware.memcached.model.MemcachedVo;
import com.monitor.model.response.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
... ... @@ -25,6 +24,15 @@ import java.util.*;
public class MemcachedCtrl {
public static final Logger DEBUG = LoggerFactory.getLogger(MemcachedCtrl.class);
private static final String AWS_JAVA_L1 = "aws_java_l1";
private static final String AWS_JAVA_L2 = "aws_java_l2";
private static final String QCLOUD_JAVA_L1 = "qcloud_java_l1";
private static final String QCLOUD_JAVA_L2 = "qcloud_java_l2";
@Autowired
IMObjectInfoService imObjectInfoService;
... ... @@ -46,25 +54,69 @@ public class MemcachedCtrl {
}
}
//排序:先按照l1、l2拆分,再对11、l2根据ip排序,最后合并
List<MemcachedVo> l1List = new ArrayList<>();
List<MemcachedVo> l2List = new ArrayList<>();
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("java_l1_memcached")){
l1List.add(vo);
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{
l2List.add(vo);
qcloud2.add(vo);
}
}
Collections.sort(l1List, new URLComparator());
Collections.sort(l2List, new URLComparator());
l1List.addAll(l2List);
response.setData(l1List);
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));
}
response.setData(result);
return response;
}
/**
* 合并同类的memcached
* @param list
*/
private MemcachedVo mergeMemcacheVo(List<MemcachedVo> list,String name) {
MemcachedVo temp = list.get(0);
temp.setName(name);
for(int i=1;i<list.size();i++){
MemcachedVo vo = list.get(i);
temp.setUpTime(temp.getUpTime()+"\r\n"+vo.getUpTime());
temp.setUrl(temp.getUrl()+"\r\n"+vo.getUrl());
temp.setHitRate(temp.getHitRate()+"\r\n"+vo.getHitRate());
temp.setUseMemory(temp.getUseMemory()+"\r\n"+vo.getUseMemory());
temp.setCurItems(temp.getCurItems()+"\r\n"+vo.getCurItems());
temp.setMaxMemory(temp.getMaxMemory()+"\r\n"+vo.getMaxMemory());
temp.setCmdGet(temp.getCmdGet()+"\r\n"+vo.getCmdGet());
temp.setCmdSet(temp.getCmdSet()+"\r\n"+vo.getCmdSet());
temp.setCurConnections(temp.getCurConnections()+"\r\n"+vo.getCurConnections());
}
return temp;
}
/**
* 组装返回对象
* @param info
* @param vo
... ...
... ... @@ -9,11 +9,11 @@ import lombok.Data;
public class MemcachedInfo {
private String upTime; //运行时间
private Integer curItems; //当前items数量
private String curItems; //当前items数量
private String useMemory; //使用内存
private Integer curConnections; //当前连接数
private String curConnections; //当前连接数
private Double cmdGet; //get频率,单位为秒
... ...
... ... @@ -9,11 +9,11 @@ import lombok.Data;
public class MemcachedVo {
private String upTime; //运行时间
private Integer curItems; //当前items数量
private String curItems; //当前items数量
private String useMemory; //使用内存
private Integer curConnections; //当前连接数
private String curConnections; //当前连接数
private String cmdGet; //get频率,单位为秒
... ...
... ... @@ -132,8 +132,8 @@ public class MemcachedMonitorImpl {
long oldSet = MemConstants.MEMCACHED_INFO_MAP.get(url).getOldSet();
info.setCmdSet((cmdSet - oldSet) / 120.0);
}
info.setCurConnections(Integer.parseInt(value.get("curr_connections")));
info.setCurItems(Integer.parseInt(value.get("curr_items")));
info.setCurConnections(value.get("curr_connections"));
info.setCurItems(value.get("curr_items"));
long get_hit = Long.parseLong(value.get("get_hits"));
long get_misses = Long.parseLong(value.get("get_misses"));
long limit_maxbytes = Long.parseLong(value.get("limit_maxbytes"));
... ... @@ -178,7 +178,8 @@ public class MemcachedMonitorImpl {
for (InetSocketAddress address: monitorUrlSet) {
failUrl.append(address.toString()+" ");
//获取失败时从缓存中移除数据
MemConstants.MEMCACHED_INFO_MAP.remove(address.toString().substring(1,address.toString().length()));
// MemConstants.MEMCACHED_INFO_MAP.remove(address.toString().substring(1,address.toString().length()));
MemConstants.MEMCACHED_INFO_MAP.put(address.toString().substring(1,address.toString().length()),new MemcachedInfo());
}
alarmMsgService.sendSms("Memcached", "Failed to get Memcached status" + failUrl.toString() + " .", snsMobileConfig.getBaseMobile());
... ...