Authored by skinny.wu

redis redis 添加信息日志

1 package com.monitor.middleware.redis.service.impl; 1 package com.monitor.middleware.redis.service.impl;
2 2
  3 +import com.alibaba.fastjson.JSONArray;
3 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
4 import com.model.MObjectInfo; 5 import com.model.MObjectInfo;
5 import com.model.RedisMonitor; 6 import com.model.RedisMonitor;
@@ -106,6 +107,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService @@ -106,6 +107,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
106 //遍历twemproxy 107 //遍历twemproxy
107 Map<String,List<String>> tMap=new HashMap<String,List<String>>(); 108 Map<String,List<String>> tMap=new HashMap<String,List<String>>();
108 List<String> ipList=null; 109 List<String> ipList=null;
  110 +
109 for(MObjectInfo obj:redisProxymList){ 111 for(MObjectInfo obj:redisProxymList){
110 paramMonitor=new StringBuffer(); 112 paramMonitor=new StringBuffer();
111 String[] ports=obj.getMoTags().split(","); 113 String[] ports=obj.getMoTags().split(",");
@@ -142,6 +144,12 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService @@ -142,6 +144,12 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
142 paramMonitor.append("当前连接数:"+curr_connections+";"); 144 paramMonitor.append("当前连接数:"+curr_connections+";");
143 } 145 }
144 146
  147 + //记录temproxy开启时间
  148 + if (upTime > 0) {
  149 + paramMonitor.append("upTime:" + upTime + ";");
  150 + log.info("upTime is : " + upTime);
  151 + }
  152 +
145 //查看代理下的redis 求出所有代理request总量 153 //查看代理下的redis 求出所有代理request总量
146 JSONObject alpha=response.getJSONObject("alpha"); 154 JSONObject alpha=response.getJSONObject("alpha");
147 ipList=new ArrayList<String>(); 155 ipList=new ArrayList<String>();
@@ -155,16 +163,12 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService @@ -155,16 +163,12 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
155 // 取出requests的long值 163 // 取出requests的long值
156 requestCount += Long.valueOf(ipObj.get("requests").toString()); 164 requestCount += Long.valueOf(ipObj.get("requests").toString());
157 redisCount ++; 165 redisCount ++;
  166 + log.info("ip:" + key + "request:" + requestCount);
158 } 167 }
159 } 168 }
160 169
161 ipString = obj.getMoHostIp()+":"+ports[1]; 170 ipString = obj.getMoHostIp()+":"+ports[1];
162 171
163 - tMap.put(obj.getMoHostIp()+":"+ports[1],ipList);  
164 - redisMonitor.setIsFailed(1);  
165 - redisMonitor.setParamMonitor(paramMonitor.toString());  
166 - }  
167 -  
168 /** 172 /**
169 * 计算caps值 (当前requestCount - lastRequestCount)/ (uptime - lastUpTime)/ 1000 173 * 计算caps值 (当前requestCount - lastRequestCount)/ (uptime - lastUpTime)/ 1000
170 * 在param_monitor字段数据中中添加 caps值 uptime值 174 * 在param_monitor字段数据中中添加 caps值 uptime值
@@ -173,7 +177,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService @@ -173,7 +177,7 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
173 double caps = -1; 177 double caps = -1;
174 178
175 //如果数据为0,即没有探测出数据,不记录该干扰数据 179 //如果数据为0,即没有探测出数据,不记录该干扰数据
176 - if (0 < requestCount || 0 < upTime) { 180 + if (0 < requestCount && 0 < upTime) {
177 181
178 //如果map中有该ip的数据,则计算caps值以及记录当前request跟uptime字段值到map中 182 //如果map中有该ip的数据,则计算caps值以及记录当前request跟uptime字段值到map中
179 if (null != lastRequestCountMap.get(ipString) 183 if (null != lastRequestCountMap.get(ipString)
@@ -187,11 +191,18 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService @@ -187,11 +191,18 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
187 //将当前的uptime request数据存到map中 191 //将当前的uptime request数据存到map中
188 lastRequestCountMap.put(ipString, requestCount); 192 lastRequestCountMap.put(ipString, requestCount);
189 lastUpTimeMap.put(ipString, upTime); 193 lastUpTimeMap.put(ipString, upTime);
  194 +
  195 + log.info("requestCount:" + requestCount + " upTime:" + upTime);
190 } 196 }
191 197
192 paramMonitor.append("caps:" + caps + ";"); 198 paramMonitor.append("caps:" + caps + ";");
193 paramMonitor.append("uptime:" + upTime + ";"); 199 paramMonitor.append("uptime:" + upTime + ";");
194 200
  201 + tMap.put(obj.getMoHostIp()+":"+ports[1],ipList);
  202 + redisMonitor.setIsFailed(1);
  203 + redisMonitor.setParamMonitor(paramMonitor.toString());
  204 + log.info("redisMonitor.setParaMonitor: " + paramMonitor.toString());
  205 + }
195 }else{ 206 }else{
196 twemproxyAlarmList.add("失败:"+obj.getMoHostIp()+":"+ports[0]); 207 twemproxyAlarmList.add("失败:"+obj.getMoHostIp()+":"+ports[0]);
197 redisMonitor.setIsFailed(0); 208 redisMonitor.setIsFailed(0);
@@ -276,6 +287,9 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService @@ -276,6 +287,9 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService
276 ***********************************************************************/ 287 ***********************************************************************/
277 if(!CollectionUtils.isEmpty(redisInfoList)){ 288 if(!CollectionUtils.isEmpty(redisInfoList)){
278 log.info("bachInsertRedisMonitor redis monitor:"+redisInfoList); 289 log.info("bachInsertRedisMonitor redis monitor:"+redisInfoList);
  290 + log.info("monitorInsertJSON:"+ JSONArray.toJSONString(redisAlarmList));
  291 + log.info("lastRequestCountMap:" + JSONObject.toJSONString(lastRequestCountMap));
  292 + log.info("lastUpTimeMap:" + JSONObject.toJSONString(lastUpTimeMap));
279 redisMonitorMapper.deleteAllRedisMonitor(); 293 redisMonitorMapper.deleteAllRedisMonitor();
280 redisMonitorMapper.bachInsertRedisMonitor(redisInfoList); 294 redisMonitorMapper.bachInsertRedisMonitor(redisInfoList);
281 } 295 }