|
|
package com.monitor.middleware.redis.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.model.MObjectInfo;
|
|
|
import com.model.RedisInfo;
|
|
|
import com.monitor.common.util.HttpRestClient;
|
|
|
import com.monitor.common.util.RedisInfo;
|
|
|
import com.monitor.common.util.RedisInfoUtil;
|
|
|
import com.monitor.middleware.redis.service.IRedisMonitorService;
|
|
|
import com.monitor.mysql.mapper.RedisMonitorMapper;
|
|
|
import com.monitor.mysql.mapper.MObjectInfoMapper;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -21,26 +24,30 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { |
|
|
|
|
|
Logger log = LoggerFactory.getLogger(RedisMonitorServiceImpl.class);
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
RedisMonitorMapper redisMonitorMapper;
|
|
|
HttpRestClient httpRestClient;
|
|
|
|
|
|
@Autowired
|
|
|
HttpRestClient httpRestClient;
|
|
|
MObjectInfoMapper mObjectInfoMapper;
|
|
|
|
|
|
@Override
|
|
|
public void redisMonitor() {
|
|
|
/**********************************************************************
|
|
|
*1、处理twemproxy
|
|
|
***********************************************************************/
|
|
|
List<com.model.RedisInfo> proxyList=redisMonitorMapper.selectRedisMonitorByLevel(1);
|
|
|
if(CollectionUtils.isEmpty(proxyList)){
|
|
|
List<RedisInfo> redisInfoList=new ArrayList<RedisInfo>();
|
|
|
redisInfoList.add(new RedisInfo("AWS","AWS",0,null));
|
|
|
redisInfoList.add(new RedisInfo("Qcloud","Qcloud",0,null));
|
|
|
RedisInfo redisInfo=null;
|
|
|
List<MObjectInfo> mlist= mObjectInfoMapper.getMoInfosByAlias("com_twemproxy");
|
|
|
if(CollectionUtils.isEmpty(mlist)){
|
|
|
return;
|
|
|
}
|
|
|
StringBuffer paramMonitor=null;
|
|
|
//遍历twemproxy
|
|
|
Map<String,List<String>> tMap=new HashMap<String,List<String>>();
|
|
|
List<String> ipList=null;
|
|
|
for(com.model.RedisInfo obj:proxyList){
|
|
|
for(MObjectInfo obj:mlist){
|
|
|
paramMonitor=new StringBuffer();
|
|
|
//JSONObject response=httpRestClient.defaultPost(obj.getHostIp()+obj.getParamMonitor(), null, JSONObject.class);
|
|
|
JSONObject response=httpRestClient.defaultPost("http://192.168.102.222:22222", null, JSONObject.class);
|
...
|
...
|
@@ -62,10 +69,20 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { |
|
|
ipList.add(key);
|
|
|
}
|
|
|
}
|
|
|
tMap.put(obj.getHostIp(),ipList);
|
|
|
tMap.put(obj.getMoHostIp(),ipList);
|
|
|
}
|
|
|
obj.setParamMonitor(paramMonitor.toString());
|
|
|
redisMonitorMapper.updateByPrimaryKey(obj);
|
|
|
redisInfo = new RedisInfo();
|
|
|
if(StringUtils.isNotBlank(obj.getMoName()) && obj.getMoName().contains("aws")){
|
|
|
redisInfo.setNodeFrom("AWS");
|
|
|
}else if(obj.getMoName().contains("qq")){
|
|
|
redisInfo.setNodeFrom("Qcloud");
|
|
|
}
|
|
|
redisInfo.setNodeTo(obj.getMoHostIp());
|
|
|
redisInfo.setLevel(1);
|
|
|
redisInfo.setParamMonitor(paramMonitor.toString());
|
|
|
redisInfoList.add(redisInfo);
|
|
|
//obj.setParamMonitor(paramMonitor.toString());
|
|
|
//redisMonitorMapper.updateByPrimaryKey(obj);
|
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
...
|
...
|
@@ -74,7 +91,7 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { |
|
|
if(tMap.size()==0){
|
|
|
return;
|
|
|
}
|
|
|
Map<String,Object> rMap=new HashMap<String,Object>();
|
|
|
|
|
|
for (Map.Entry<String, List<String>> entry : tMap.entrySet()) {
|
|
|
String key = entry.getKey().toString();
|
|
|
List<String> rlist = entry.getValue();
|
...
|
...
|
@@ -83,12 +100,21 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { |
|
|
String[] ipConfig=ipStr.split(":");
|
|
|
Map<String,Object> result=null;
|
|
|
if(ipConfig.length==2){
|
|
|
result=RedisInfo.getRedisInfo(ipConfig[0],Integer.valueOf(ipConfig[1]));
|
|
|
rMap.put(ipConfig[0],result);
|
|
|
result= RedisInfoUtil.getRedisInfo(ipConfig[0], Integer.valueOf(ipConfig[1]));
|
|
|
paramMonitor=new StringBuffer();
|
|
|
if(null==result){
|
|
|
paramMonitor.append("状态:宕机;");
|
|
|
}else{
|
|
|
String role=(String)result.get("role");
|
|
|
paramMonitor.append("角色:"+role+";");
|
|
|
paramMonitor.append("用量:"+result.get("used_memory_rss")+";");
|
|
|
paramMonitor.append("内存碎片比率:" + result.get("mem_fragmentation_ratio") + ";");
|
|
|
// paramMonitor.append(":"+isSlave+";");
|
|
|
}
|
|
|
redisInfoList.add(new RedisInfo(key,ipStr,3,paramMonitor.toString()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|