...
|
...
|
@@ -51,6 +51,10 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService |
|
|
|
|
|
@Autowired
|
|
|
private SnsMobileConfig snsMobileConfig;
|
|
|
|
|
|
private static Map<String, Long> lastUpTimeMap = new HashMap<>();
|
|
|
|
|
|
private static Map<String, Long> lastRequestCountMap = new HashMap<>();
|
|
|
|
|
|
@Override
|
|
|
public void redisMonitor() {
|
...
|
...
|
@@ -104,7 +108,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService |
|
|
List<String> ipList=null;
|
|
|
for(MObjectInfo obj:redisProxymList){
|
|
|
paramMonitor=new StringBuffer();
|
|
|
String[] 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();
|
...
|
...
|
@@ -117,9 +121,19 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService |
|
|
}
|
|
|
//取舍成功重新设为1
|
|
|
JSONObject response=JSONObject.parseObject(result);
|
|
|
|
|
|
//记录代理所有request的和
|
|
|
long requestCount = 0;
|
|
|
long upTime = -1;
|
|
|
int redisCount = 0;
|
|
|
|
|
|
//用ipString作为lastRequestCountMap lastUpTimeMap中的key
|
|
|
String ipString ="";
|
|
|
|
|
|
if(null != response){
|
|
|
int total_connections=(Integer)response.get("total_connections");
|
|
|
int curr_connections=(Integer)response.get("curr_connections");
|
|
|
upTime = (long)response.get("uptime");
|
|
|
if(total_connections>0){
|
|
|
//总连接数
|
|
|
paramMonitor.append("总连接数:"+total_connections+";");
|
...
|
...
|
@@ -127,19 +141,57 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService |
|
|
if (total_connections > 0) {
|
|
|
paramMonitor.append("当前连接数:"+curr_connections+";");
|
|
|
}
|
|
|
//查看代理下的redis
|
|
|
|
|
|
//查看代理下的redis 求出所有代理request总量
|
|
|
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+":"+obj.getMoTypeId());
|
|
|
JSONObject ipObj= alpha.getJSONObject(key);
|
|
|
|
|
|
// 取出requests的long值
|
|
|
requestCount += (long)ipObj.get("requests");
|
|
|
redisCount ++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ipString = obj.getMoHostIp()+":"+ports[1];
|
|
|
|
|
|
tMap.put(obj.getMoHostIp()+":"+ports[1],ipList);
|
|
|
redisMonitor.setIsFailed(1);
|
|
|
redisMonitor.setParamMonitor(paramMonitor.toString());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计算caps值 (当前requestCount - lastRequestCount)/ (uptime - lastUpTime)/ 1000
|
|
|
* 在param_monitor字段数据中中添加 caps值 uptime值
|
|
|
* 将caps uptime数据存到全局map中,供下次计算使用
|
|
|
*/
|
|
|
double caps = -1;
|
|
|
|
|
|
//如果数据为0,即没有探测出数据,不记录该干扰数据
|
|
|
if (0 < requestCount || 0 < upTime) {
|
|
|
|
|
|
//如果map中有该ip的数据,则计算caps值以及记录当前request跟uptime字段值到map中
|
|
|
if (null != lastRequestCountMap.get(ipString)
|
|
|
&& null != lastUpTimeMap.get(ipString)) {
|
|
|
|
|
|
long lastRequestCount = lastRequestCountMap.get(ipString);
|
|
|
long lastUpTime = lastUpTimeMap.get(ipString);
|
|
|
caps = (requestCount - lastRequestCount) * 1.0 / ((upTime - lastUpTime) * 1000) / redisCount;
|
|
|
}
|
|
|
|
|
|
//将当前的uptime request数据存到map中
|
|
|
lastRequestCountMap.put(ipString, requestCount);
|
|
|
lastUpTimeMap.put(ipString, upTime);
|
|
|
}
|
|
|
|
|
|
paramMonitor.append("caps:" + caps + ";");
|
|
|
paramMonitor.append("uptime:" + upTime + ";");
|
|
|
|
|
|
}else{
|
|
|
twemproxyAlarmList.add("失败:"+obj.getMoHostIp()+":"+ports[0]);
|
|
|
redisMonitor.setIsFailed(0);
|
...
|
...
|
|