Authored by simba

update

... ... @@ -11,6 +11,28 @@ import java.util.Map;
public class RedisCommonUtil {
public static long getRedisMaxMemory(String host,int port){
Map<String,Object> result=null;
Jedis client =null;
try {
client=new Jedis(host, port);
result=new HashMap<String, Object>();
List<String> configList=client.configGet("maxmemory");
long maxmemory=0;
if(!CollectionUtils.isEmpty(configList)&&configList.size()==2){
maxmemory=Long.valueOf(configList.get(1));
}
return maxmemory;
}catch (Exception e){
return 0;
}finally {
if(client!=null){
client.close();
}
}
}
public static Map<String,Object> getRedisInfo(String host,int port){
Map<String,Object> result=null;
Jedis client =null;
... ... @@ -21,12 +43,6 @@ public class RedisCommonUtil {
return null;
}
result=new HashMap<String, Object>();
List<String> configList=client.configGet("maxmemory");
int maxmemory=0;
if(!CollectionUtils.isEmpty(configList)&&configList.size()==2){
maxmemory=Integer.valueOf(configList.get(1));
}
result.put("maxmemory",maxmemory);
String[] arr = redisInfo.split("\r\n");
for (String str : arr) {
if (str.startsWith("#")||str.startsWith("\r\n")) {
... ...
... ... @@ -96,19 +96,17 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
List<String> ipList=null;
for(MObjectInfo obj:redisProxymList){
paramMonitor=new StringBuffer();
String[] ports=null;
if(StringUtils.isBlank(obj.getMoTags())){
ports=obj.getMoTags().split(",");
}
String[] ports=obj.getMoTags().split(",");;
log.info("two port is {}",obj.getMoTags());
String result= TelnetUtils.getResult(obj.getMoHostIp(),Integer.valueOf(ports[0]));
redisMonitor = new RedisMonitor();
if(StringUtils.isNotBlank(result)){
paramMonitor.append("1,");
boolean proxyFlag=RedisCommonUtil.getRedisIsSlave(obj.getMoHostIp(),Integer.valueOf(ports[1]));
if(proxyFlag){
paramMonitor.append("OK,");
paramMonitor.append("探测成功;");
}else{
paramMonitor.append("ERROR,");
paramMonitor.append("探测失败;");
}
//取舍成功重新设为1
JSONObject response=JSONObject.parseObject(result);
... ... @@ -117,10 +115,10 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
int curr_connections=(Integer)response.get("curr_connections");
if(total_connections>0){
//总连接数
paramMonitor.append(total_connections+",");
paramMonitor.append("总连接数:"+total_connections+";");
}
if (total_connections > 0) {
paramMonitor.append(curr_connections+",");
paramMonitor.append("当前连接数:"+curr_connections+";");
}
//查看代理下的redis
JSONObject alpha=response.getJSONObject("alpha");
... ... @@ -131,7 +129,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
ipList.add(key+":"+obj.getMoTypeId());
}
}
tMap.put(obj.getMoHostIp()+":"+obj.getMoTags(),ipList);
tMap.put(obj.getMoHostIp()+":"+ports[1],ipList);
redisMonitor.setIsFailed(1);
redisMonitor.setParamMonitor(paramMonitor.toString());
}
... ... @@ -141,7 +139,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
redisMonitor.setParamMonitor("0,");
}
redisMonitor.setNodeFrom(redisTweproxyMap.get(obj.getMoTypeId()));
redisMonitor.setNodeTo(obj.getMoHostIp()+":"+obj.getMoTags());
redisMonitor.setNodeTo(obj.getMoHostIp()+":"+ports[1]);
redisMonitor.setLevel(1);
redisMonitor.setRedisType(obj.getMoTypeId());
redisInfoList.add(redisMonitor);
... ... @@ -175,13 +173,18 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
String role=(String)result.get("role");
paramMonitor.append(role+",");
try {
BigDecimal maxmemory=BigDecimal.valueOf(Long.valueOf(result.get("maxmemory").toString()));
BigDecimal byteDang=BigDecimal.valueOf(Long.valueOf(1024*1024));
BigDecimal maxMemoryMb = maxmemory.divide(byteDang,2,4);
paramMonitor.append(maxMemoryMb+"M,");
BigDecimal used_memory=BigDecimal.valueOf(Long.valueOf(result.get("used_memory").toString()));
BigDecimal useProportion = used_memory.divide(maxmemory,2,4);
paramMonitor.append(useProportion+"%,");
long maxmemory=RedisCommonUtil.getRedisMaxMemory(ipConfig[0], Integer.valueOf(ipConfig[1]));
if(maxmemory==0){
paramMonitor.append("最大内存为0");
}else{
BigDecimal byteDang=BigDecimal.valueOf(Long.valueOf(1024*1024));
BigDecimal maxMemoryMb = BigDecimal.valueOf(maxmemory).divide(byteDang,2,4);
paramMonitor.append(maxMemoryMb+"M,");
BigDecimal used_memory=BigDecimal.valueOf(Long.valueOf(result.get("used_memory").toString()));
BigDecimal useProportion = used_memory.divide(BigDecimal.valueOf(maxmemory),2,4);
paramMonitor.append(useProportion+"%,");
}
}catch (Exception e){
log.error("计算Redis使用率错误",e);
paramMonitor.append("0.00%,");
... ...
... ... @@ -13,7 +13,7 @@ public class RedisMonitorTask {
private IRedisMonitorHandleService redisMonitorService;
//@Scheduled(fixedRate=20000)
@Scheduled(cron="0 0/5 * * * ? ")
@Scheduled(cron="0 0/3 * * * ? ")
public void redisMonitor(){
redisMonitorService.redisMonitor();
}
... ...