Authored by jack

增加独立redis监控

@@ -96,8 +96,10 @@ public class OverViewJob implements Callable { @@ -96,8 +96,10 @@ public class OverViewJob implements Callable {
96 if (null != oneView) { 96 if (null != oneView) {
97 InterVar.overViewMaps.put(moId, overViewModel); 97 InterVar.overViewMaps.put(moId, overViewModel);
98 } else { 98 } else {
  99 + if (InterVar.overViewMaps.containsKey(moId)) {
99 InterVar.overViewMaps.get(moId).setState(overViewModel.getState()); 100 InterVar.overViewMaps.get(moId).setState(overViewModel.getState());
100 } 101 }
  102 + }
101 103
102 DEBUG.info("End to execute over view job in moid {}", this.moId); 104 DEBUG.info("End to execute over view job in moid {}", this.moId);
103 } 105 }
@@ -94,7 +94,7 @@ public class QueueViewJob implements Callable { @@ -94,7 +94,7 @@ public class QueueViewJob implements Callable {
94 return; 94 return;
95 } catch (Exception e) { 95 } catch (Exception e) {
96 96
97 - DEBUG.error("Failed to execute monitor task , error {} ", e); 97 + DEBUG.error("Failed to execute queue view task , error {} ", e);
98 98
99 return; 99 return;
100 } 100 }
@@ -67,6 +67,13 @@ public class TwemproxyInfo { @@ -67,6 +67,13 @@ public class TwemproxyInfo {
67 } 67 }
68 } 68 }
69 69
  70 + public TwemproxyInfo(String ip, int port) {
  71 +
  72 + this.ip = ip;
  73 +
  74 + this.port = port;
  75 + }
  76 +
70 77
71 public void buildServersInfoByRelations(Map<String, String> relationMaps) { 78 public void buildServersInfoByRelations(Map<String, String> relationMaps) {
72 79
@@ -164,7 +164,7 @@ public class RedisMonitorImpl { @@ -164,7 +164,7 @@ public class RedisMonitorImpl {
164 return null; 164 return null;
165 } 165 }
166 166
167 - TwemproxyTask twemproxyTask = new TwemproxyTask(url, mPort, name, mObjectInfo.getMoId(), alarmMsgService, snsMobileConfig); 167 + TwemproxyTask twemproxyTask = new TwemproxyTask(url, mPort, name, mObjectInfo, alarmMsgService, snsMobileConfig);
168 168
169 twemproxyTask.setMObjectInfoList(mObjectInfos); 169 twemproxyTask.setMObjectInfoList(mObjectInfos);
170 170
@@ -24,20 +24,20 @@ import java.util.concurrent.Executors; @@ -24,20 +24,20 @@ import java.util.concurrent.Executors;
24 * Created by yoho on 2016/9/20. 24 * Created by yoho on 2016/9/20.
25 */ 25 */
26 public class TwemproxyTask extends Task { 26 public class TwemproxyTask extends Task {
27 - 27 + private static final String STANDALONE = "0.0.0.0";
28 28
29 private int monitPort; 29 private int monitPort;
30 30
31 private String name; 31 private String name;
32 32
33 - private int moId; 33 + private MObjectInfo moInfo;
34 34
35 @Getter 35 @Getter
36 @Setter 36 @Setter
37 private List<MObjectInfo> mObjectInfoList; 37 private List<MObjectInfo> mObjectInfoList;
38 38
39 39
40 - public TwemproxyTask(String url, int monitPort, String name, int moId, AlarmMsgService alarmMsgService, 40 + public TwemproxyTask(String url, int monitPort, String name, MObjectInfo moInfo, AlarmMsgService alarmMsgService,
41 SnsMobileConfig snsMobileConfig) { 41 SnsMobileConfig snsMobileConfig) {
42 42
43 super(url, alarmMsgService, snsMobileConfig); 43 super(url, alarmMsgService, snsMobileConfig);
@@ -46,7 +46,7 @@ public class TwemproxyTask extends Task { @@ -46,7 +46,7 @@ public class TwemproxyTask extends Task {
46 46
47 this.name = name; 47 this.name = name;
48 48
49 - this.moId = moId; 49 + this.moInfo = moInfo;
50 50
51 } 51 }
52 52
@@ -54,6 +54,13 @@ public class TwemproxyTask extends Task { @@ -54,6 +54,13 @@ public class TwemproxyTask extends Task {
54 @Override 54 @Override
55 public void doTask() { 55 public void doTask() {
56 56
  57 + //独立redis的伪twemproxy
  58 + if (StringUtils.equals(STANDALONE, moInfo.getMoHostIp())) {
  59 + doAloneTask();
  60 +
  61 + return;
  62 + }
  63 +
57 String info = TelnetUtils.getResult(this.getIp(), this.monitPort); 64 String info = TelnetUtils.getResult(this.getIp(), this.monitPort);
58 65
59 TwemproxyInfo twemproxyInfo = null; 66 TwemproxyInfo twemproxyInfo = null;
@@ -73,7 +80,7 @@ public class TwemproxyTask extends Task { @@ -73,7 +80,7 @@ public class TwemproxyTask extends Task {
73 80
74 twemproxyInfo.setType(name); 81 twemproxyInfo.setType(name);
75 82
76 - twemproxyInfo.setMoId(String.valueOf(this.moId)); 83 + twemproxyInfo.setMoId(String.valueOf(this.moInfo.getMoId()));
77 84
78 //构建redis与twemproxy的关系 85 //构建redis与twemproxy的关系
79 Map<String, String> relationMaps = new HashMap<>(); 86 Map<String, String> relationMaps = new HashMap<>();
@@ -192,4 +199,48 @@ public class TwemproxyTask extends Task { @@ -192,4 +199,48 @@ public class TwemproxyTask extends Task {
192 return true; 199 return true;
193 } 200 }
194 201
  202 +
  203 + //伪twemproxy构造
  204 + private void doAloneTask() {
  205 + TwemproxyInfo twemproxyInfo = new TwemproxyInfo(STANDALONE, 6379);
  206 +
  207 + twemproxyInfo.setUpTime(0);
  208 +
  209 + twemproxyInfo.setType(name);
  210 +
  211 + twemproxyInfo.setMoId(String.valueOf(this.moInfo.getMoId()));
  212 +
  213 + twemproxyInfo.setCurrConnections(0);
  214 +
  215 + twemproxyInfo.setState("OK");
  216 +
  217 + Map<String, Long> requestMap = new HashMap<>();
  218 +
  219 + for (MObjectInfo mObjectInfo : mObjectInfoList) {
  220 +
  221 + String tags[] = mObjectInfo.getMoTags().split(",");
  222 +
  223 + String port = "";
  224 +
  225 + for (String tag : tags) {
  226 +
  227 + if (tag.startsWith("port:")) {
  228 + port = tag.split(":", 2)[1];
  229 + }
  230 + }
  231 +
  232 + if (StringUtils.isNotBlank(port)) {
  233 +
  234 + requestMap.put(mObjectInfo.getMoHostIp() + ":" + port, 0L);
  235 + }
  236 + }
  237 +
  238 + twemproxyInfo.setRequestMap(requestMap);
  239 +
  240 + //存储
  241 + Constants.TWEMPROXY_INFO_MAP.put(this.getUrl(), twemproxyInfo);
  242 +
  243 + dispatchRedisTask(twemproxyInfo);
  244 + }
  245 +
195 } 246 }