|
|
package com.monitor.middleware.redis.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.model.MObjectInfo;
|
|
|
import com.model.RedisMonitor;
|
...
|
...
|
@@ -106,6 +107,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService |
|
|
//遍历twemproxy
|
|
|
Map<String,List<String>> tMap=new HashMap<String,List<String>>();
|
|
|
List<String> ipList=null;
|
|
|
|
|
|
for(MObjectInfo obj:redisProxymList){
|
|
|
paramMonitor=new StringBuffer();
|
|
|
String[] ports=obj.getMoTags().split(",");
|
...
|
...
|
@@ -142,6 +144,12 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService |
|
|
paramMonitor.append("当前连接数:"+curr_connections+";");
|
|
|
}
|
|
|
|
|
|
//记录temproxy开启时间
|
|
|
if (upTime > 0) {
|
|
|
paramMonitor.append("upTime:" + upTime + ";");
|
|
|
log.info("upTime is : " + upTime);
|
|
|
}
|
|
|
|
|
|
//查看代理下的redis 求出所有代理request总量
|
|
|
JSONObject alpha=response.getJSONObject("alpha");
|
|
|
ipList=new ArrayList<String>();
|
...
|
...
|
@@ -155,43 +163,46 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService |
|
|
// 取出requests的long值
|
|
|
requestCount += Long.valueOf(ipObj.get("requests").toString());
|
|
|
redisCount ++;
|
|
|
log.info("ip:" + key + "request:" + requestCount);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
/**
|
|
|
* 计算caps值 (当前requestCount - lastRequestCount)/ (uptime - lastUpTime)/ 1000
|
|
|
* 在param_monitor字段数据中中添加 caps值 uptime值
|
|
|
* 将caps uptime数据存到全局map中,供下次计算使用
|
|
|
*/
|
|
|
double caps = -1;
|
|
|
//如果数据为0,即没有探测出数据,不记录该干扰数据
|
|
|
if (0 < requestCount && 0 < upTime) {
|
|
|
|
|
|
//如果数据为0,即没有探测出数据,不记录该干扰数据
|
|
|
if (0 < requestCount || 0 < upTime) {
|
|
|
//如果map中有该ip的数据,则计算caps值以及记录当前request跟uptime字段值到map中
|
|
|
if (null != lastRequestCountMap.get(ipString)
|
|
|
&& null != lastUpTimeMap.get(ipString)) {
|
|
|
|
|
|
//如果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;
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
//将当前的uptime request数据存到map中
|
|
|
lastRequestCountMap.put(ipString, requestCount);
|
|
|
lastUpTimeMap.put(ipString, upTime);
|
|
|
}
|
|
|
log.info("requestCount:" + requestCount + " upTime:" + upTime);
|
|
|
}
|
|
|
|
|
|
paramMonitor.append("caps:" + caps + ";");
|
|
|
paramMonitor.append("uptime:" + upTime + ";");
|
|
|
paramMonitor.append("caps:" + caps + ";");
|
|
|
paramMonitor.append("uptime:" + upTime + ";");
|
|
|
|
|
|
tMap.put(obj.getMoHostIp()+":"+ports[1],ipList);
|
|
|
redisMonitor.setIsFailed(1);
|
|
|
redisMonitor.setParamMonitor(paramMonitor.toString());
|
|
|
log.info("redisMonitor.setParaMonitor: " + paramMonitor.toString());
|
|
|
}
|
|
|
}else{
|
|
|
twemproxyAlarmList.add("失败:"+obj.getMoHostIp()+":"+ports[0]);
|
|
|
redisMonitor.setIsFailed(0);
|
...
|
...
|
@@ -276,6 +287,9 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService |
|
|
***********************************************************************/
|
|
|
if(!CollectionUtils.isEmpty(redisInfoList)){
|
|
|
log.info("bachInsertRedisMonitor redis monitor:"+redisInfoList);
|
|
|
log.info("monitorInsertJSON:"+ JSONArray.toJSONString(redisAlarmList));
|
|
|
log.info("lastRequestCountMap:" + JSONObject.toJSONString(lastRequestCountMap));
|
|
|
log.info("lastUpTimeMap:" + JSONObject.toJSONString(lastUpTimeMap));
|
|
|
redisMonitorMapper.deleteAllRedisMonitor();
|
|
|
redisMonitorMapper.bachInsertRedisMonitor(redisInfoList);
|
|
|
}
|
...
|
...
|
|