|
|
package com.monitor.middleware.redis.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.model.RedisInfo;
|
|
|
import com.monitor.common.util.HttpRestClient;
|
|
|
import com.monitor.common.util.SSHRedis;
|
|
|
import com.monitor.common.util.RedisInfo;
|
|
|
import com.monitor.middleware.redis.service.IRedisMonitorService;
|
|
|
import com.monitor.mysql.mapper.RedisMonitorMapper;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class RedisMonitorServiceImpl implements IRedisMonitorService {
|
...
|
...
|
@@ -29,23 +30,65 @@ public class RedisMonitorServiceImpl implements IRedisMonitorService { |
|
|
|
|
|
@Override
|
|
|
public void redisMonitor() {
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public String getRedisInfo(String redisInfo, String info) {
|
|
|
|
|
|
String[] arry = redisInfo.split("<br>");
|
|
|
for (int i = 0; i < arry.length; i++) {
|
|
|
String[] b = arry[i].replace("\r\n", "").split(":");
|
|
|
for (int j = 0; j < b.length; j++) {
|
|
|
if (b[j].equals(info)) {
|
|
|
return b[1].trim();
|
|
|
/**********************************************************************
|
|
|
*1、处理twemproxy
|
|
|
***********************************************************************/
|
|
|
List<com.model.RedisInfo> proxyList=redisMonitorMapper.selectRedisMonitorByLevel(1);
|
|
|
if(CollectionUtils.isEmpty(proxyList)){
|
|
|
return;
|
|
|
}
|
|
|
StringBuffer paramMonitor=null;
|
|
|
Map<String,List<String>> tMap=new HashMap<String,List<String>>();
|
|
|
List<String> ipList=null;
|
|
|
for(com.model.RedisInfo obj:proxyList){
|
|
|
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);
|
|
|
if(null != response){
|
|
|
int total_connections=(Integer)response.get("total_connections");
|
|
|
int curr_connections=(Integer)response.get("curr_connections");
|
|
|
if(total_connections>0){
|
|
|
paramMonitor.append("总连接数:"+total_connections);
|
|
|
}
|
|
|
if (total_connections > 0) {
|
|
|
paramMonitor.append("当前接数:"+curr_connections);
|
|
|
}
|
|
|
//查看代理下的redis
|
|
|
JSONObject alpha=response.getJSONObject("alpha");
|
|
|
ipList=new ArrayList<String>();
|
|
|
for (Map.Entry<String, Object> entry : alpha.entrySet()) {
|
|
|
String key=entry.getKey();
|
|
|
if(key.indexOf(":")>1){
|
|
|
ipList.add(key);
|
|
|
}
|
|
|
}
|
|
|
tMap.put(obj.getHostIp(),ipList);
|
|
|
}
|
|
|
obj.setParamMonitor(paramMonitor.toString());
|
|
|
redisMonitorMapper.updateByPrimaryKey(obj);
|
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
|
|
*2、处理Redis
|
|
|
***********************************************************************/
|
|
|
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();
|
|
|
if(!CollectionUtils.isEmpty(rlist)){
|
|
|
for(String ipStr:rlist){
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|