Authored by skinny.wu

dns monitor 添加当前监控数据 存储在内存中

@@ -111,9 +111,9 @@ public class ZkMoitorServiceImpl implements IZkMoitorService { @@ -111,9 +111,9 @@ public class ZkMoitorServiceImpl implements IZkMoitorService {
111 zkConfig.setName(chi); 111 zkConfig.setName(chi);
112 zkConfig.setRoot(rootString); 112 zkConfig.setRoot(rootString);
113 zkConfig.setIp(req.getIp()); 113 zkConfig.setIp(req.getIp());
114 -// if(chi.equals("config")){ 114 + if(chi.equals("config")){
115 list.add(zkConfig); 115 list.add(zkConfig);
116 -// } 116 + }
117 117
118 page++; 118 page++;
119 } 119 }
@@ -37,8 +37,8 @@ public class DNSMonitorMapperImpl implements IDNSMonitorMapper{ @@ -37,8 +37,8 @@ public class DNSMonitorMapperImpl implements IDNSMonitorMapper{
37 .addField("info", info).build(); 37 .addField("info", info).build();
38 38
39 batchPoints.point(point); 39 batchPoints.point(point);
40 - inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()  
41 - .write(batchPoints); 40 +// inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
  41 +// .write(batchPoints);
42 } 42 }
43 43
44 /** 44 /**
@@ -77,7 +77,7 @@ public class DNSMonitorMapperImpl implements IDNSMonitorMapper{ @@ -77,7 +77,7 @@ public class DNSMonitorMapperImpl implements IDNSMonitorMapper{
77 } 77 }
78 78
79 batchPoints.point(point); 79 batchPoints.point(point);
80 - inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()  
81 - .write(batchPoints); 80 +// inluxDBSingle.getInfluxDBByName(InfluxDBContants.AWS).getInfluxDB()
  81 +// .write(batchPoints);
82 } 82 }
83 } 83 }
1 package com.monitor.other.dns.constant; 1 package com.monitor.other.dns.constant;
2 2
  3 +import com.monitor.other.dns.model.HostDNSConnectModel;
  4 +
  5 +import java.util.ArrayList;
  6 +import java.util.List;
  7 +
3 /** 8 /**
4 * Created by yoho on 2016/8/3. 9 * Created by yoho on 2016/8/3.
5 */ 10 */
@@ -16,4 +21,16 @@ public interface InterVar { @@ -16,4 +21,16 @@ public interface InterVar {
16 String RESPONSE_CODE_200 = "200"; 21 String RESPONSE_CODE_200 = "200";
17 22
18 String STRING_CODE = "code"; 23 String STRING_CODE = "code";
  24 +
  25 + String LOCK = "lock";
  26 +
  27 + String SUCCESSED = "SUCCESSED";
  28 +
  29 + String FAILED = "failed";
  30 +
  31 + String HTTP_STATUS_CODE_NOT_200 = "HTTP_STATUS_CODE_NOT_200";
  32 +
  33 + String RETURN_DATA_CODE_NOT_200 = "RETURN_DATA_CODE_NOT_200";
  34 +
  35 + List<HostDNSConnectModel> hostDNSConnectModelList = new ArrayList<>();
19 } 36 }
  1 +package com.monitor.other.dns.ctrl;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.monitor.other.dns.constant.InterVar;
  5 +import org.springframework.stereotype.Controller;
  6 +import org.springframework.web.bind.annotation.RequestMapping;
  7 +import org.springframework.web.bind.annotation.ResponseBody;
  8 +
  9 +/**
  10 + * Created by yoho on 2016/8/4.
  11 + */
  12 +@Controller
  13 +@RequestMapping("/other/dns_monitor")
  14 +public class DNSMonitorCtrl {
  15 +
  16 + @RequestMapping("/current")
  17 + @ResponseBody
  18 + public String getCurrentInfo() {
  19 + return JSON.toJSONString(InterVar.hostDNSConnectModelList);
  20 + }
  21 +}
  1 +package com.monitor.other.dns.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.util.List;
  6 +import java.util.Map;
  7 +
  8 +/**
  9 + * Created by yoho on 2016/8/4.
  10 + */
  11 +public class HostDNSConnectModel {
  12 +
  13 + String host;
  14 +
  15 + /**
  16 + * key为uid value为host+uid对应的ip以及检测状态
  17 + */
  18 + Map<String, List<IPConnectModel>> ips;
  19 +
  20 + public String getHost() {
  21 + return host;
  22 + }
  23 +
  24 + public Map<String, List<IPConnectModel>> getIps() {
  25 + return ips;
  26 + }
  27 +
  28 + public HostDNSConnectModel() {}
  29 +
  30 + public HostDNSConnectModel(String host) {
  31 + this.host = host;
  32 + }
  33 +
  34 + public void setIps(Map<String, List<IPConnectModel>> ips) {
  35 + this.ips = ips;
  36 + }
  37 +}
1 package com.monitor.other.dns.model; 1 package com.monitor.other.dns.model;
2 2
  3 +import lombok.Data;
  4 +
3 /** 5 /**
4 * Created by yoho on 2016/8/3. 6 * Created by yoho on 2016/8/3.
5 */ 7 */
6 public class IPConnectModel { 8 public class IPConnectModel {
7 9
8 /** 10 /**
9 - * 对应域名 11 + * 解析出的ip
10 */ 12 */
11 - String host; 13 + String ip;
12 14
13 /** 15 /**
14 - * 解析出的ip 16 + * 状态
15 */ 17 */
16 - String ip; 18 + String status;
17 19
18 /** 20 /**
19 - * 链接相应 21 + * 信息
20 */ 22 */
21 - String response; 23 + String info;
  24 +
  25 + public String getIp() {
  26 + return ip;
  27 + }
  28 +
  29 + public String getStatus() {
  30 + return status;
  31 + }
  32 +
  33 + public String getInfo() {
  34 + return info;
  35 + }
  36 +
  37 + public IPConnectModel() {}
  38 +
  39 + public IPConnectModel(String ip, String status, String info) {
  40 + this.ip = ip;
  41 + this.status = status;
  42 + this.info = info;
  43 + }
22 } 44 }
@@ -9,6 +9,8 @@ import com.monitor.influxdb.mapper.IDNSMonitorMapper; @@ -9,6 +9,8 @@ import com.monitor.influxdb.mapper.IDNSMonitorMapper;
9 import com.monitor.other.dns.common.DNSConfig; 9 import com.monitor.other.dns.common.DNSConfig;
10 import com.monitor.other.dns.constant.InterVar; 10 import com.monitor.other.dns.constant.InterVar;
11 import com.monitor.other.dns.model.DNSIPsModel; 11 import com.monitor.other.dns.model.DNSIPsModel;
  12 +import com.monitor.other.dns.model.HostDNSConnectModel;
  13 +import com.monitor.other.dns.model.IPConnectModel;
12 import com.monitor.other.dns.model.IPModel; 14 import com.monitor.other.dns.model.IPModel;
13 import com.monitor.other.dns.service.IDNSMonitorService; 15 import com.monitor.other.dns.service.IDNSMonitorService;
14 import com.monitor.other.dns.service.IRestTemplateNoEncode; 16 import com.monitor.other.dns.service.IRestTemplateNoEncode;
@@ -21,7 +23,9 @@ import org.springframework.beans.factory.annotation.Value; @@ -21,7 +23,9 @@ import org.springframework.beans.factory.annotation.Value;
21 import org.springframework.stereotype.Service; 23 import org.springframework.stereotype.Service;
22 24
23 import java.util.ArrayList; 25 import java.util.ArrayList;
  26 +import java.util.HashMap;
24 import java.util.List; 27 import java.util.List;
  28 +import java.util.Map;
25 29
26 /** 30 /**
27 * Created by yoho on 2016/8/1. 31 * Created by yoho on 2016/8/1.
@@ -58,27 +62,45 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ @@ -58,27 +62,45 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{
58 */ 62 */
59 @Override 63 @Override
60 public void monitor() { 64 public void monitor() {
  65 + List<HostDNSConnectModel> hostDNSConnectModelList = new ArrayList<>();
61 66
62 for (String host : dnsConfig.getHosts()) { 67 for (String host : dnsConfig.getHosts()) {
63 - for (String id : dnsConfig.getUids()) {  
64 68
65 - String result = restTemplateNoEncode.doGet(buildDNSUrl(host,id));  
66 - List<IPModel> ipModelList = parseIPModels(result); 69 + HostDNSConnectModel hostDNSConnectModel = new HostDNSConnectModel(host);
  70 +
  71 + //key为uid value为host+uid下的ip以及其状态
  72 + Map<String, List<IPConnectModel>> ipConnectModelsMap = new HashMap<>();
  73 +
  74 + for (String uid : dnsConfig.getUids()) {
  75 +
  76 + String result = restTemplateNoEncode.doGet(buildDNSUrl(host,uid));
  77 + List<String> ipModelList = parseIPModels(result);
67 78
68 - //调用dns api无返回ip,即异常,发送告警短信,把数据存数influxdb中  
69 if (null == ipModelList) { 79 if (null == ipModelList) {
70 - alarmMsgService.sendSms("dns_exception", buildDNSFailedMsnContent(host, id), 80 +
  81 + //短信告警
  82 + alarmMsgService.sendSms("dns_exception", buildDNSFailedMsnContent(host, uid),
71 result, alarmMobile); 83 result, alarmMobile);
  84 + //host dns 检测数据存入influxdb
  85 + dnsMonitorMapper.insert(host, uid, IDNSMonitorMapper.FAILED, IDNSMonitorMapper.NULL_IP);
  86 +
  87 + ipConnectModelsMap.put(uid, null);
72 logger.error("DNSMonitor Connect DNS no ip return.host:{},uid{}", 88 logger.error("DNSMonitor Connect DNS no ip return.host:{},uid{}",
73 - host, id);  
74 - dnsMonitorMapper.insert(host, id, IDNSMonitorMapper.FAILED, IDNSMonitorMapper.NULL_IP); 89 + host, uid);
75 continue; 90 continue;
76 } 91 }
77 92
78 - dnsMonitorMapper.insert(host, id, IDNSMonitorMapper.SUCCESSED, JSONArray.toJSONString(ipModelList));  
79 - monitIPConnection(host, id, ipModelList); 93 + //host dns 检测数据存入influxdb
  94 + dnsMonitorMapper.insert(host, uid, IDNSMonitorMapper.SUCCESSED, JSONArray.toJSONString(ipModelList));
  95 +
  96 + monitIPConnection(host, uid, ipModelList, ipConnectModelsMap);
80 } 97 }
  98 + hostDNSConnectModel.setIps(ipConnectModelsMap);
  99 + hostDNSConnectModelList.add(hostDNSConnectModel);
81 } 100 }
  101 +
  102 + InterVar.hostDNSConnectModelList.clear();
  103 + InterVar.hostDNSConnectModelList.addAll(hostDNSConnectModelList);
82 } 104 }
83 105
84 /** 106 /**
@@ -86,14 +108,15 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ @@ -86,14 +108,15 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{
86 * 108 *
87 * m.yoho.com域名返回为网页,其他域名不注明则为api接口 109 * m.yoho.com域名返回为网页,其他域名不注明则为api接口
88 * @param host 110 * @param host
89 - * @param ipModelList 111 + * @param ipList
90 */ 112 */
91 - private void monitIPConnection(String host,String uid, List<IPModel> ipModelList) { 113 + private void monitIPConnection(String host,String uid, List<String> ipList,
  114 + Map<String, List<IPConnectModel>> ipConnectionMaps) {
92 115
93 if (InterVar.M_YOHOBUY_COM.equals(host)) { 116 if (InterVar.M_YOHOBUY_COM.equals(host)) {
94 - monitMYohoBuyComIp(host, uid, ipModelList); 117 + monitMYohoBuyComIp(host, uid, ipList, ipConnectionMaps);
95 } else { 118 } else {
96 - monitApiIp(host, uid, ipModelList); 119 + monitApiIp(host, uid, ipList, ipConnectionMaps);
97 } 120 }
98 } 121 }
99 122
@@ -101,33 +124,37 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ @@ -101,33 +124,37 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{
101 * 124 *
102 * @param host 125 * @param host
103 * @param uid 126 * @param uid
104 - * @param ipModelList 127 + * @param ipList
105 */ 128 */
106 - private void monitApiIp(String host, String uid, List<IPModel> ipModelList) { 129 + private void monitApiIp(String host, String uid, List<String> ipList,
  130 + Map<String, List<IPConnectModel>> ipConnectionMap) {
107 List<String> errorIPs = new ArrayList<>(); 131 List<String> errorIPs = new ArrayList<>();
108 StringBuilder alarmInfo = new StringBuilder(); 132 StringBuilder alarmInfo = new StringBuilder();
  133 + List<IPConnectModel> ipConnectModels = new ArrayList<>();
109 134
110 - for (IPModel ipModel : ipModelList) { 135 + for (String ip : ipList) {
111 136
112 String responseCode = restTemplateNoEncode.doGetResponseCode( 137 String responseCode = restTemplateNoEncode.doGetResponseCode(
113 - InterVar.HTTP + ipModel.getIp() + dnsConfig.getServices().get(host)); 138 + InterVar.HTTP + ip + dnsConfig.getServices().get(host));
114 139
115 //ip不通,告警 140 //ip不通,告警
116 if (!InterVar.RESPONSE_CODE_200.equals(responseCode) || null == responseCode) { 141 if (!InterVar.RESPONSE_CODE_200.equals(responseCode) || null == responseCode) {
117 - errorIPs.add(ipModel.getIp()); 142 + errorIPs.add(ip);
118 alarmInfo.append(" ip: "); 143 alarmInfo.append(" ip: ");
119 - alarmInfo.append(ipModel.getIp()); 144 + alarmInfo.append(ip);
120 alarmInfo.append(" 不通. "); 145 alarmInfo.append(" 不通. ");
121 logger.error("DNSMonitor Connect DNS API: host {}, uid {}, ip {} 不通。", 146 logger.error("DNSMonitor Connect DNS API: host {}, uid {}, ip {} 不通。",
122 - host, uid, ipModel.getIp());  
123 - dnsMonitorMapper.insert(host, uid, ipModel.getIp(),  
124 - IDNSMonitorMapper.FAILED, IDNSMonitorMapper.HTTP_STATUS_CODE_NOT_200, ""); 147 + host, uid, ip);
  148 + dnsMonitorMapper.insert(host, uid, ip, IDNSMonitorMapper.FAILED,
  149 + IDNSMonitorMapper.HTTP_STATUS_CODE_NOT_200, "");
  150 +
  151 + ipConnectModels.add(new IPConnectModel(ip, InterVar.FAILED, InterVar.HTTP_STATUS_CODE_NOT_200));
125 continue; 152 continue;
126 } 153 }
127 154
128 //获取服务请求返回的数据是否正确 code:200 155 //获取服务请求返回的数据是否正确 code:200
129 String response = httpRestClientService.doGet( 156 String response = httpRestClientService.doGet(
130 - InterVar.HTTP + ipModel.getIp() + dnsConfig.getServices().get(host), null); 157 + InterVar.HTTP + ip + dnsConfig.getServices().get(host), null);
131 158
132 String resultCode = null; 159 String resultCode = null;
133 160
@@ -140,32 +167,36 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ @@ -140,32 +167,36 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{
140 167
141 //返回数据 code!=200 告警 168 //返回数据 code!=200 告警
142 if (!InterVar.RESPONSE_CODE_200.equals(resultCode) || null == response) { 169 if (!InterVar.RESPONSE_CODE_200.equals(resultCode) || null == response) {
143 - errorIPs.add(ipModel.getIp()); 170 + errorIPs.add(ip);
144 171
145 alarmInfo.append(" ip: "); 172 alarmInfo.append(" ip: ");
146 - alarmInfo.append(ipModel.getIp()); 173 + alarmInfo.append(ip);
147 alarmInfo.append(";response: "); 174 alarmInfo.append(";response: ");
148 alarmInfo.append(response); 175 alarmInfo.append(response);
149 alarmInfo.append(". "); 176 alarmInfo.append(". ");
150 logger.info("DNSMonitor Connect DNS API: host {}, uid {}, ip {}, response {} ", 177 logger.info("DNSMonitor Connect DNS API: host {}, uid {}, ip {}, response {} ",
151 - host, uid, ipModel.getIp(), response); 178 + host, uid, ip, response);
152 179
153 - dnsMonitorMapper.insert(host, uid, ipModel.getIp(), 180 + dnsMonitorMapper.insert(host, uid, ip,
154 IDNSMonitorMapper.FAILED, IDNSMonitorMapper.RETURN_DATA_CODE_NOT_200, 181 IDNSMonitorMapper.FAILED, IDNSMonitorMapper.RETURN_DATA_CODE_NOT_200,
155 response); 182 response);
  183 + ipConnectModels.add(new IPConnectModel(ip, InterVar.FAILED, InterVar.RETURN_DATA_CODE_NOT_200));
156 continue; 184 continue;
157 } 185 }
158 186
159 - dnsMonitorMapper.insert(host, uid, ipModel.getIp(), IDNSMonitorMapper.SUCCESSED, "", ""); 187 + dnsMonitorMapper.insert(host, uid, ip, IDNSMonitorMapper.SUCCESSED, "", "");
  188 + ipConnectModels.add(new IPConnectModel(ip, InterVar.SUCCESSED, ""));
160 } 189 }
161 190
  191 + ipConnectionMap.put(uid, ipConnectModels);
  192 +
162 if (!errorIPs.isEmpty()) { 193 if (!errorIPs.isEmpty()) {
163 alarmMsgService.sendSms("dns_exception", 194 alarmMsgService.sendSms("dns_exception",
164 - buildIPConnectFailedMsnContent(host, uid, ipModelList, errorIPs), 195 + buildIPConnectFailedMsnContent(host, uid, ipList, errorIPs),
165 alarmInfo.toString(), alarmMobile); 196 alarmInfo.toString(), alarmMobile);
166 197
167 logger.error("DNSMonitor Connect DNS API: host {}, uid {}, dnsIP {}, connextFailedIP {}", 198 logger.error("DNSMonitor Connect DNS API: host {}, uid {}, dnsIP {}, connextFailedIP {}",
168 - host, uid, ipModelList.toString(), errorIPs.toString()); 199 + host, uid, ipList.toString(), errorIPs.toString());
169 } 200 }
170 } 201 }
171 202
@@ -176,55 +207,63 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ @@ -176,55 +207,63 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{
176 * 2.返回预期数据 207 * 2.返回预期数据
177 * @param host 208 * @param host
178 * @param uid 209 * @param uid
179 - * @param ipModelList 210 + * @param ipList
180 */ 211 */
181 - private void monitMYohoBuyComIp(String host, String uid, List<IPModel> ipModelList) { 212 + private void monitMYohoBuyComIp(String host, String uid, List<String> ipList,
  213 + Map<String, List<IPConnectModel>> ipConnectionMap) {
182 List<String> errorIPs = new ArrayList<>(); 214 List<String> errorIPs = new ArrayList<>();
183 StringBuilder alarmInfo = new StringBuilder(); 215 StringBuilder alarmInfo = new StringBuilder();
  216 + List<IPConnectModel> ipConnectModels = new ArrayList<>();
184 217
185 - for (IPModel ipModel : ipModelList) { 218 + for (String ip : ipList) {
186 219
187 - String responseCode = restTemplateNoEncode.doGetResponseCode(InterVar.HTTPS + ipModel.getIp()); 220 + String responseCode = restTemplateNoEncode.doGetResponseCode(InterVar.HTTPS + ip);
188 221
189 //ip不通,异常数据告警 222 //ip不通,异常数据告警
190 if (!InterVar.RESPONSE_CODE_200.equals(responseCode) || null == responseCode) { 223 if (!InterVar.RESPONSE_CODE_200.equals(responseCode) || null == responseCode) {
191 - errorIPs.add(ipModel.getIp()); 224 + errorIPs.add(ip);
192 alarmInfo.append(" ip: "); 225 alarmInfo.append(" ip: ");
193 - alarmInfo.append(ipModel.getIp()); 226 + alarmInfo.append(ip);
194 alarmInfo.append(" 不通. "); 227 alarmInfo.append(" 不通. ");
195 logger.info("DNSMonitor Connect DNS API: host {}, uid {}, ip {} 不通。", 228 logger.info("DNSMonitor Connect DNS API: host {}, uid {}, ip {} 不通。",
196 - host, uid, ipModel.getIp());  
197 - dnsMonitorMapper.insert(host, uid, ipModel.getIp(), 229 + host, uid, ip);
  230 + dnsMonitorMapper.insert(host, uid, ip,
198 IDNSMonitorMapper.FAILED, IDNSMonitorMapper.HTTP_STATUS_CODE_NOT_200, ""); 231 IDNSMonitorMapper.FAILED, IDNSMonitorMapper.HTTP_STATUS_CODE_NOT_200, "");
  232 +
  233 + ipConnectModels.add(new IPConnectModel(ip, InterVar.FAILED, InterVar.HTTP_STATUS_CODE_NOT_200));
199 continue; 234 continue;
200 } 235 }
201 236
202 //检测该ip是否返回预期网页 237 //检测该ip是否返回预期网页
203 String response = restTemplateNoEncode.doGet( 238 String response = restTemplateNoEncode.doGet(
204 - InterVar.HTTPS + ipModel.getIp() + dnsConfig.getServices().get(host)); 239 + InterVar.HTTPS + ip + dnsConfig.getServices().get(host));
205 240
206 //验证返回网页是否正确 如果不含有该字符串则返回结果错误 241 //验证返回网页是否正确 如果不含有该字符串则返回结果错误
207 if (-1 == response.indexOf(InterVar.M_YOHOBUY_COM_RESPONSE_PATTEN) || null == response) { 242 if (-1 == response.indexOf(InterVar.M_YOHOBUY_COM_RESPONSE_PATTEN) || null == response) {
208 - errorIPs.add(ipModel.getIp()); 243 + errorIPs.add(ip);
209 alarmInfo.append(" ip: "); 244 alarmInfo.append(" ip: ");
210 - alarmInfo.append(ipModel.getIp()); 245 + alarmInfo.append(ip);
211 alarmInfo.append(" 返回网页错误. "); 246 alarmInfo.append(" 返回网页错误. ");
212 - dnsMonitorMapper.insert(host, uid, ipModel.getIp(), 247 + dnsMonitorMapper.insert(host, uid, ip,
213 IDNSMonitorMapper.FAILED, IDNSMonitorMapper.RETURN_DATA_CODE_NOT_200, response); 248 IDNSMonitorMapper.FAILED, IDNSMonitorMapper.RETURN_DATA_CODE_NOT_200, response);
214 logger.info("DNSMonitor Connect DNS API: host {}, uid {}, ip {} 结果错误。", 249 logger.info("DNSMonitor Connect DNS API: host {}, uid {}, ip {} 结果错误。",
215 - host, uid, ipModel.getIp()); 250 + host, uid, ip);
  251 + ipConnectModels.add(new IPConnectModel(ip, InterVar.FAILED, InterVar.RETURN_DATA_CODE_NOT_200));
216 continue; 252 continue;
217 } 253 }
218 254
219 - dnsMonitorMapper.insert(host, uid, ipModel.getIp(), IDNSMonitorMapper.SUCCESSED, "", ""); 255 + dnsMonitorMapper.insert(host, uid, ip, IDNSMonitorMapper.SUCCESSED, "", "");
  256 + ipConnectModels.add(new IPConnectModel(ip, InterVar.SUCCESSED, ""));
220 } 257 }
221 258
  259 + ipConnectionMap.put(uid, ipConnectModels);
  260 +
222 if (!errorIPs.isEmpty()) { 261 if (!errorIPs.isEmpty()) {
223 alarmMsgService.sendSms("dns_exception", 262 alarmMsgService.sendSms("dns_exception",
224 - buildIPConnectFailedMsnContent(host, uid, ipModelList, errorIPs), 263 + buildIPConnectFailedMsnContent(host, uid, ipList, errorIPs),
225 alarmInfo.toString(), alarmMobile); 264 alarmInfo.toString(), alarmMobile);
226 logger.error("DNSMonitor Connect DNS API: host {}, uid {}, dnsIP {}, connextFailedIP {}", 265 logger.error("DNSMonitor Connect DNS API: host {}, uid {}, dnsIP {}, connextFailedIP {}",
227 - host, uid, ipModelList.toString(), errorIPs.toString()); 266 + host, uid, ipList.toString(), errorIPs.toString());
228 } 267 }
229 } 268 }
230 269
@@ -235,13 +274,21 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ @@ -235,13 +274,21 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{
235 * @param result 274 * @param result
236 * @return 275 * @return
237 */ 276 */
238 - private List<IPModel> parseIPModels(String result) { 277 + private List<String> parseIPModels(String result) {
239 String decodeResult = AESUtil.decode(result); 278 String decodeResult = AESUtil.decode(result);
240 279
241 DNSIPsModel dnsiPsModel = JSON.parseObject(decodeResult, DNSIPsModel.class); 280 DNSIPsModel dnsiPsModel = JSON.parseObject(decodeResult, DNSIPsModel.class);
242 List<IPModel> ipModelList = JSON.parseArray(dnsiPsModel.getContent() , IPModel.class); 281 List<IPModel> ipModelList = JSON.parseArray(dnsiPsModel.getContent() , IPModel.class);
243 282
244 - return ipModelList; 283 + if (null == ipModelList) {
  284 + return null;
  285 + }
  286 +
  287 + List<String> ipList = new ArrayList<String>();
  288 + for (IPModel ipModel : ipModelList) {
  289 + ipList.add(ipModel.getIp());
  290 + }
  291 + return ipList;
245 } 292 }
246 293
247 /** 294 /**
@@ -269,7 +316,7 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{ @@ -269,7 +316,7 @@ public class DNSMonitorServiceImpl implements IDNSMonitorService{
269 * @param connectFailedIps 访问失败的ip组 316 * @param connectFailedIps 访问失败的ip组
270 * @return 317 * @return
271 */ 318 */
272 - private String buildIPConnectFailedMsnContent(String host, String uid, List<IPModel> ips, 319 + private String buildIPConnectFailedMsnContent(String host, String uid, List<String> ips,
273 List<String> connectFailedIps) { 320 List<String> connectFailedIps) {
274 StringBuilder sb = new StringBuilder(); 321 StringBuilder sb = new StringBuilder();
275 sb.append("DNS解析IP错误!"); 322 sb.append("DNS解析IP错误!");
1 package com.monitor.other.dns.task; 1 package com.monitor.other.dns.task;
2 2
  3 +import com.monitor.other.dns.constant.InterVar;
3 import com.monitor.other.dns.service.IDNSMonitorService; 4 import com.monitor.other.dns.service.IDNSMonitorService;
4 import org.springframework.beans.factory.annotation.Autowired; 5 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.scheduling.annotation.Scheduled; 6 import org.springframework.scheduling.annotation.Scheduled;
@@ -16,6 +17,8 @@ public class DNSMonitorTask { @@ -16,6 +17,8 @@ public class DNSMonitorTask {
16 17
17 @Scheduled(cron = "${cron_task_dns_monit}") 18 @Scheduled(cron = "${cron_task_dns_monit}")
18 public void monitor() { 19 public void monitor() {
  20 + synchronized (InterVar.LOCK.intern()) {
19 dnsMonitorService.monitor(); 21 dnsMonitorService.monitor();
20 } 22 }
  23 + }
21 } 24 }
1 # ******************** dns monitor common configs ******************** 1 # ******************** dns monitor common configs ********************
2 dns.config.url=api.yoho.cn/?method=app.resources.config.clientInitConfig&client_secret=bf8f49754dc7058349146f922640000c&client_type=android;service.yoho.cn/?method=app.resources.config.clientInitConfig&client_secret=bf8f49754dc7058349146f922640000c&client_type=android;m.yohobuy.com/boys 2 dns.config.url=api.yoho.cn/?method=app.resources.config.clientInitConfig&client_secret=bf8f49754dc7058349146f922640000c&client_type=android;service.yoho.cn/?method=app.resources.config.clientInitConfig&client_secret=bf8f49754dc7058349146f922640000c&client_type=android;m.yohobuy.com/boys
3 -#dns.config.hosts=api.yoho.cn;service.yoho.cn;m.yohobuy.com  
4 -#dns.config.services=/?method=app.resources.config.clientInitConfig&client_secret=bf8f49754dc7058349146f922640000c&client_type=android;/operations/api/v5/resource/get?app_version=3.9.0.1512170008&client_secret=00be285c73a816177652240fea5a4a54&client_type=iphone&content_code=a7989369aa86681c678bc40f171b8f1d&os_version=9.2&screen_size=375x667&v=7;/boys  
5 3
6 dns.config.api.url=http://123.206.2.55/? 4 dns.config.api.url=http://123.206.2.55/?
@@ -10,5 +10,5 @@ cron_task_rabbit_monit=0 0/2 * * * ? @@ -10,5 +10,5 @@ cron_task_rabbit_monit=0 0/2 * * * ?
10 10
11 cron_task_rabbit_scan=0 0/1 * * * ? 11 cron_task_rabbit_scan=0 0/1 * * * ?
12 12
13 -cron_task_dns_monit=0 0/3 * * * ? 13 +cron_task_dns_monit=0 1/5 * * * ?
14 14