Merge branch 'master' of http://git.yoho.cn/ops/monitor-service
Showing
5 changed files
with
50 additions
and
11 deletions
monitor-service-middleware/src/main/java/com/monitor/middleware/rabbitmq/component/AlarmMsgComp.java
@@ -2,15 +2,20 @@ package com.monitor.middleware.rabbitmq.component; | @@ -2,15 +2,20 @@ package com.monitor.middleware.rabbitmq.component; | ||
2 | 2 | ||
3 | import com.monitor.common.config.SnsMobileConfig; | 3 | import com.monitor.common.config.SnsMobileConfig; |
4 | import com.monitor.common.service.AlarmMsgService; | 4 | import com.monitor.common.service.AlarmMsgService; |
5 | +import org.slf4j.Logger; | ||
6 | +import org.slf4j.LoggerFactory; | ||
5 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
6 | import org.springframework.stereotype.Component; | 8 | import org.springframework.stereotype.Component; |
7 | 9 | ||
10 | + | ||
8 | /** | 11 | /** |
9 | * Created by yoho on 2016/7/6. | 12 | * Created by yoho on 2016/7/6. |
10 | */ | 13 | */ |
11 | @Component | 14 | @Component |
12 | public class AlarmMsgComp { | 15 | public class AlarmMsgComp { |
13 | 16 | ||
17 | + public static final Logger DEBUG = LoggerFactory.getLogger(AlarmMsgComp.class); | ||
18 | + | ||
14 | @Autowired | 19 | @Autowired |
15 | AlarmMsgService alarmMsgService; | 20 | AlarmMsgService alarmMsgService; |
16 | 21 | ||
@@ -18,7 +23,13 @@ public class AlarmMsgComp { | @@ -18,7 +23,13 @@ public class AlarmMsgComp { | ||
18 | SnsMobileConfig snsMobileConfig; | 23 | SnsMobileConfig snsMobileConfig; |
19 | 24 | ||
20 | public void doAlarm(String subject, String content) { | 25 | public void doAlarm(String subject, String content) { |
21 | - alarmMsgService.sendSms(subject, content, snsMobileConfig.getBaseMobile()); | ||
22 | - } | ||
23 | 26 | ||
27 | + try { | ||
28 | + alarmMsgService.sendSms(subject, content, snsMobileConfig.getBaseMobile()); | ||
29 | + } catch (Exception e) { | ||
30 | + DEBUG.error("Failed to alarm , error {}", e); | ||
31 | + return; | ||
32 | + } | ||
33 | + | ||
34 | + } | ||
24 | } | 35 | } |
@@ -57,7 +57,7 @@ public interface InterVar { | @@ -57,7 +57,7 @@ public interface InterVar { | ||
57 | 57 | ||
58 | String DBTAG = "moId"; | 58 | String DBTAG = "moId"; |
59 | 59 | ||
60 | - int MONIT_TIMEOUT = 10; | 60 | + int MONIT_TIMEOUT = 30; |
61 | 61 | ||
62 | String RETENTION_POLICY = "default"; | 62 | String RETENTION_POLICY = "default"; |
63 | 63 |
@@ -51,7 +51,7 @@ public class RabbitMonitTask { | @@ -51,7 +51,7 @@ public class RabbitMonitTask { | ||
51 | @Autowired | 51 | @Autowired |
52 | AlarmMsgComp alarmMsgComp; | 52 | AlarmMsgComp alarmMsgComp; |
53 | 53 | ||
54 | - @Scheduled(fixedRate = 3 * 60 * 1000L) | 54 | + @Scheduled(fixedRate = 2 * 60 * 1000L) |
55 | public void doTask() { | 55 | public void doTask() { |
56 | synchronized (InterVar.LOCK.intern()) { | 56 | synchronized (InterVar.LOCK.intern()) { |
57 | for (Map.Entry<Integer, MObjectInfo> entry : InterVar.moMaps.entrySet()) { | 57 | for (Map.Entry<Integer, MObjectInfo> entry : InterVar.moMaps.entrySet()) { |
1 | package com.monitor.middleware.rabbitmq.task; | 1 | package com.monitor.middleware.rabbitmq.task; |
2 | 2 | ||
3 | import com.model.MObjectInfo; | 3 | import com.model.MObjectInfo; |
4 | +import com.model.RabbitAlertInfo; | ||
4 | import com.model.TypeInfo; | 5 | import com.model.TypeInfo; |
5 | import com.monitor.cmdb.service.IMObjectInfoService; | 6 | import com.monitor.cmdb.service.IMObjectInfoService; |
6 | import com.monitor.cmdb.service.ITypeInfoService; | 7 | import com.monitor.cmdb.service.ITypeInfoService; |
7 | import com.monitor.middleware.rabbitmq.constant.InterVar; | 8 | import com.monitor.middleware.rabbitmq.constant.InterVar; |
9 | +import com.monitor.mysql.mapper.RabbitAlertMapper; | ||
8 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
9 | import org.springframework.context.annotation.EnableAspectJAutoProxy; | 11 | import org.springframework.context.annotation.EnableAspectJAutoProxy; |
10 | import org.springframework.scheduling.annotation.EnableAsync; | 12 | import org.springframework.scheduling.annotation.EnableAsync; |
@@ -14,6 +16,7 @@ import org.springframework.stereotype.Component; | @@ -14,6 +16,7 @@ import org.springframework.stereotype.Component; | ||
14 | 16 | ||
15 | import javax.annotation.PostConstruct; | 17 | import javax.annotation.PostConstruct; |
16 | import java.util.ArrayList; | 18 | import java.util.ArrayList; |
19 | +import java.util.HashMap; | ||
17 | import java.util.List; | 20 | import java.util.List; |
18 | 21 | ||
19 | /** | 22 | /** |
@@ -29,14 +32,16 @@ public class RabbitScanTask implements Runnable { | @@ -29,14 +32,16 @@ public class RabbitScanTask implements Runnable { | ||
29 | @Autowired | 32 | @Autowired |
30 | ITypeInfoService typeService; | 33 | ITypeInfoService typeService; |
31 | 34 | ||
35 | + @Autowired | ||
36 | + RabbitAlertMapper rabbitAlertMapper; | ||
37 | + | ||
32 | @PostConstruct | 38 | @PostConstruct |
33 | - public void init() | ||
34 | - { | 39 | + public void init() { |
35 | InterVar.EXECUTOR_SERVICE.submit(this); | 40 | InterVar.EXECUTOR_SERVICE.submit(this); |
36 | } | 41 | } |
37 | 42 | ||
38 | //自动发现rabbit监控对象 | 43 | //自动发现rabbit监控对象 |
39 | - @Scheduled(fixedRate = 60*1000L) | 44 | + @Scheduled(fixedRate = 60 * 1000L) |
40 | public void doTask() { | 45 | public void doTask() { |
41 | 46 | ||
42 | List<TypeInfo> typeInfosList = typeService.queryAllTypesInfo(); | 47 | List<TypeInfo> typeInfosList = typeService.queryAllTypesInfo(); |
@@ -51,13 +56,30 @@ public class RabbitScanTask implements Runnable { | @@ -51,13 +56,30 @@ public class RabbitScanTask implements Runnable { | ||
51 | } | 56 | } |
52 | } | 57 | } |
53 | 58 | ||
54 | - synchronized (InterVar.LOCK.intern()) | ||
55 | - { | 59 | + synchronized (InterVar.LOCK.intern()) { |
60 | + | ||
56 | for (MObjectInfo info : mObjectInfoList) { | 61 | for (MObjectInfo info : mObjectInfoList) { |
57 | 62 | ||
58 | InterVar.moMaps.put(info.getMoId(), info); | 63 | InterVar.moMaps.put(info.getMoId(), info); |
59 | } | 64 | } |
65 | + | ||
66 | + for (RabbitAlertInfo info : rabbitAlertMapper.getAllAlertsInfo()) { | ||
67 | + | ||
68 | + HashMap<String, Integer> alertMap = new HashMap<>(); | ||
69 | + | ||
70 | + if (InterVar.alertMaps.containsKey(info.getMoId())) { | ||
71 | + | ||
72 | + alertMap = InterVar.alertMaps.get(info.getMoId()); | ||
73 | + } | ||
74 | + | ||
75 | + alertMap.put(info.getQueueName(), info.getAlertHigh()); | ||
76 | + | ||
77 | + InterVar.alertMaps.put(info.getMoId(), alertMap); | ||
78 | + } | ||
60 | } | 79 | } |
80 | + | ||
81 | + | ||
82 | + | ||
61 | } | 83 | } |
62 | 84 | ||
63 | 85 |
@@ -93,6 +93,12 @@ public class QueueViewJob implements Callable { | @@ -93,6 +93,12 @@ public class QueueViewJob implements Callable { | ||
93 | 93 | ||
94 | return; | 94 | return; |
95 | } | 95 | } |
96 | + catch (Exception e) | ||
97 | + { | ||
98 | + DEBUG.error("Failed to execute monitor task , error {} ",e); | ||
99 | + | ||
100 | + return; | ||
101 | + } | ||
96 | 102 | ||
97 | if (null != oneView) { | 103 | if (null != oneView) { |
98 | 104 | ||
@@ -106,7 +112,7 @@ public class QueueViewJob implements Callable { | @@ -106,7 +112,7 @@ public class QueueViewJob implements Callable { | ||
106 | private void checkAlert(String moId, QueueInfo queueInfo) { | 112 | private void checkAlert(String moId, QueueInfo queueInfo) { |
107 | 113 | ||
108 | synchronized (moId.intern()) { | 114 | synchronized (moId.intern()) { |
109 | - HashMap<String, Integer> alertMaps = InterVar.alertMaps.get(moId); | 115 | + HashMap<String, Integer> alertMaps = InterVar.alertMaps.get(Integer.parseInt(moId)); |
110 | 116 | ||
111 | if (null != alertMaps) { | 117 | if (null != alertMaps) { |
112 | 118 | ||
@@ -123,7 +129,7 @@ public class QueueViewJob implements Callable { | @@ -123,7 +129,7 @@ public class QueueViewJob implements Callable { | ||
123 | alarmMsgComp.doAlarm(InterVar.ALARM_QUEUE, msg); | 129 | alarmMsgComp.doAlarm(InterVar.ALARM_QUEUE, msg); |
124 | 130 | ||
125 | //ui alert | 131 | //ui alert |
126 | - InterVar.overViewMaps.get(this.moId).setState(0); | 132 | + InterVar.overViewMaps.get(Integer.parseInt(moId)).setState(0); |
127 | } | 133 | } |
128 | } | 134 | } |
129 | } | 135 | } |
-
Please register or login to post a comment