Showing
1 changed file
with
39 additions
and
25 deletions
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,43 +163,46 @@ public class RedisMonitorHandleServiceImpl implements IRedisMonitorHandleService | @@ -155,43 +163,46 @@ 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 | - } | 172 | + /** |
173 | + * 计算caps值 (当前requestCount - lastRequestCount)/ (uptime - lastUpTime)/ 1000 | ||
174 | + * 在param_monitor字段数据中中添加 caps值 uptime值 | ||
175 | + * 将caps uptime数据存到全局map中,供下次计算使用 | ||
176 | + */ | ||
177 | + double caps = -1; | ||
167 | 178 | ||
168 | - /** | ||
169 | - * 计算caps值 (当前requestCount - lastRequestCount)/ (uptime - lastUpTime)/ 1000 | ||
170 | - * 在param_monitor字段数据中中添加 caps值 uptime值 | ||
171 | - * 将caps uptime数据存到全局map中,供下次计算使用 | ||
172 | - */ | ||
173 | - double caps = -1; | 179 | + //如果数据为0,即没有探测出数据,不记录该干扰数据 |
180 | + if (0 < requestCount && 0 < upTime) { | ||
174 | 181 | ||
175 | - //如果数据为0,即没有探测出数据,不记录该干扰数据 | ||
176 | - if (0 < requestCount || 0 < upTime) { | 182 | + //如果map中有该ip的数据,则计算caps值以及记录当前request跟uptime字段值到map中 |
183 | + if (null != lastRequestCountMap.get(ipString) | ||
184 | + && null != lastUpTimeMap.get(ipString)) { | ||
177 | 185 | ||
178 | - //如果map中有该ip的数据,则计算caps值以及记录当前request跟uptime字段值到map中 | ||
179 | - if (null != lastRequestCountMap.get(ipString) | ||
180 | - && null != lastUpTimeMap.get(ipString)) { | 186 | + long lastRequestCount = lastRequestCountMap.get(ipString); |
187 | + long lastUpTime = lastUpTimeMap.get(ipString); | ||
188 | + caps = (requestCount - lastRequestCount) * 1.0 / ((upTime - lastUpTime) * 1000) / redisCount; | ||
189 | + } | ||
181 | 190 | ||
182 | - long lastRequestCount = lastRequestCountMap.get(ipString); | ||
183 | - long lastUpTime = lastUpTimeMap.get(ipString); | ||
184 | - caps = (requestCount - lastRequestCount) * 1.0 / ((upTime - lastUpTime) * 1000) / redisCount; | ||
185 | - } | 191 | + //将当前的uptime request数据存到map中 |
192 | + lastRequestCountMap.put(ipString, requestCount); | ||
193 | + lastUpTimeMap.put(ipString, upTime); | ||
186 | 194 | ||
187 | - //将当前的uptime request数据存到map中 | ||
188 | - lastRequestCountMap.put(ipString, requestCount); | ||
189 | - lastUpTimeMap.put(ipString, upTime); | ||
190 | - } | 195 | + log.info("requestCount:" + requestCount + " upTime:" + upTime); |
196 | + } | ||
191 | 197 | ||
192 | - paramMonitor.append("caps:" + caps + ";"); | ||
193 | - paramMonitor.append("uptime:" + upTime + ";"); | 198 | + paramMonitor.append("caps:" + caps + ";"); |
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 | } |
-
Please register or login to post a comment