Merge branch 'master' of http://git.yoho.cn/ops/monitor-service
Showing
7 changed files
with
172 additions
and
0 deletions
@@ -42,6 +42,8 @@ public class SnsMobileConfig { | @@ -42,6 +42,8 @@ public class SnsMobileConfig { | ||
42 | 42 | ||
43 | private String baseMobile; | 43 | private String baseMobile; |
44 | 44 | ||
45 | + private String testMobile; | ||
46 | + | ||
45 | @PostConstruct | 47 | @PostConstruct |
46 | public void init(){ | 48 | public void init(){ |
47 | //大数据报警 | 49 | //大数据报警 |
@@ -82,6 +84,12 @@ public class SnsMobileConfig { | @@ -82,6 +84,12 @@ public class SnsMobileConfig { | ||
82 | baseMobile=""; | 84 | baseMobile=""; |
83 | } | 85 | } |
84 | 86 | ||
87 | + //testMobile | ||
88 | + testMobile=getUsersInfoUtil.getMobileByAlarmGroup("test"); | ||
89 | + if(testMobile==null){ | ||
90 | + testMobile=""; | ||
91 | + } | ||
92 | + | ||
85 | logger.info("初始化手机号码"); | 93 | logger.info("初始化手机号码"); |
86 | logger.info("JAVAAPI错误报警 javaApiError :"+javaApiError); | 94 | logger.info("JAVAAPI错误报警 javaApiError :"+javaApiError); |
87 | logger.info("JAVAAPI错误搜索组报警 javaApiSearchError :"+javaApiSearchError); | 95 | logger.info("JAVAAPI错误搜索组报警 javaApiSearchError :"+javaApiSearchError); |
@@ -89,6 +97,7 @@ public class SnsMobileConfig { | @@ -89,6 +97,7 @@ public class SnsMobileConfig { | ||
89 | logger.info("JAVASERVICE错误报警 javaServiceMobile :"+javaServiceMobile); | 97 | logger.info("JAVASERVICE错误报警 javaServiceMobile :"+javaServiceMobile); |
90 | logger.info("REDIS异常报警 redisMobile :"+redisMobile); | 98 | logger.info("REDIS异常报警 redisMobile :"+redisMobile); |
91 | logger.info("基础组 baseMobile :"+baseMobile); | 99 | logger.info("基础组 baseMobile :"+baseMobile); |
100 | + logger.info("testMobile :"+testMobile); | ||
92 | } | 101 | } |
93 | 102 | ||
94 | } | 103 | } |
1 | +package com.monitor.influxdb.mapper.impl; | ||
2 | + | ||
3 | + | ||
4 | +import com.monitor.influxdb.InfluxDataReporter; | ||
5 | +import com.monitor.influxdb.contants.InfluxDBContants; | ||
6 | +import com.monitor.influxdb.mapper.GatewayAccessAllMapper; | ||
7 | +import com.monitor.influxdb.mapper.GatewayAccessEventsMapper; | ||
8 | +import org.influxdb.dto.QueryResult; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.stereotype.Component; | ||
11 | + | ||
12 | +@Component | ||
13 | +public class GatewayAccessAllMapperImpl implements GatewayAccessAllMapper { | ||
14 | + | ||
15 | + @Autowired | ||
16 | + private InfluxDataReporter influxDataReporter; | ||
17 | + | ||
18 | + /** | ||
19 | + * | ||
20 | + * @param influxDBName | ||
21 | + * @return | ||
22 | + */ | ||
23 | + @Override | ||
24 | + public QueryResult selectMeanValue(String influxDBName,int beforeMin,int afterMin) { | ||
25 | + String command = "SELECT mean(total_count) / 10 FROM gateway_access_all WHERE time >= now() - "+beforeMin+"m "; | ||
26 | + if(afterMin>0){ | ||
27 | + command += "and time < now() - "+afterMin +"m "; | ||
28 | + } | ||
29 | + return influxDataReporter.queryResult(influxDBName, command, InfluxDBContants.YOHO_EVENT_SAMPLE); | ||
30 | + } | ||
31 | + | ||
32 | +} |
monitor-service-other/src/main/java/com/monitor/other/task/someTask/GatewayMonitorTask.java
0 → 100644
1 | +package com.monitor.other.task.someTask; | ||
2 | + | ||
3 | +import com.monitor.common.config.SnsMobileConfig; | ||
4 | +import com.monitor.common.service.AlarmMsgService; | ||
5 | +import com.monitor.influxdb.contants.InfluxDBContants; | ||
6 | +import com.monitor.influxdb.mapper.GatewayAccessAllMapper; | ||
7 | +import com.monitor.influxdb.util.QueryResultUtil; | ||
8 | +import com.monitor.other.dockermonitor.task.DockerMonitorTask; | ||
9 | +import com.util.GetUsersInfoUtil; | ||
10 | +import org.influxdb.dto.QueryResult; | ||
11 | +import org.slf4j.Logger; | ||
12 | +import org.slf4j.LoggerFactory; | ||
13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
14 | +import org.springframework.beans.factory.annotation.Value; | ||
15 | +import org.springframework.scheduling.annotation.Scheduled; | ||
16 | +import org.springframework.stereotype.Component; | ||
17 | +import org.springframework.util.CollectionUtils; | ||
18 | + | ||
19 | +import java.text.DecimalFormat; | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | + | ||
23 | +/** | ||
24 | + * Created by craig.qin on 2018/4/3. | ||
25 | + * gateway流量有巨大变化的时候,告警 | ||
26 | + */ | ||
27 | +@Component | ||
28 | +public class GatewayMonitorTask { | ||
29 | + public static final Logger logger = LoggerFactory.getLogger(GatewayMonitorTask.class); | ||
30 | + DecimalFormat df = new DecimalFormat("######0.00"); | ||
31 | + | ||
32 | + @Autowired | ||
33 | + private GatewayAccessAllMapper gatewayAccessAllMapper; | ||
34 | + | ||
35 | + @Autowired | ||
36 | + private SnsMobileConfig snsMobileConfig; | ||
37 | + | ||
38 | + @Autowired | ||
39 | + private AlarmMsgService alarmMsgService; | ||
40 | + | ||
41 | + //当前环境 | ||
42 | + @Value("${system.envi}") | ||
43 | + private String env; | ||
44 | + | ||
45 | + @Scheduled(cron = "${cron_task_gateway_monitor_aws}") | ||
46 | + public void alarmGatewayMonitor_aws() { | ||
47 | + if("test1".equals(env)||"test".equals(env)){ | ||
48 | + return ; | ||
49 | + } | ||
50 | + alarm(InfluxDBContants.AWS); | ||
51 | + } | ||
52 | + | ||
53 | + | ||
54 | + @Scheduled(cron = "${cron_task_gateway_monitor_qcloud}") | ||
55 | + public void alarmGatewayMonitor_qcloud() { | ||
56 | + if("test1".equals(env)||"test".equals(env)){ | ||
57 | + return ; | ||
58 | + } | ||
59 | + alarm(InfluxDBContants.Q_CLOUD); | ||
60 | + } | ||
61 | + | ||
62 | + private void alarm(String influxdbName){ | ||
63 | + String mobile=snsMobileConfig.getTestMobile(); | ||
64 | + QueryResult queryResultFurther = gatewayAccessAllMapper.selectMeanValue(influxdbName,4,2); | ||
65 | + QueryResult queryResultClose = gatewayAccessAllMapper.selectMeanValue(influxdbName,2,0); | ||
66 | + if(queryResultClose==null||queryResultFurther==null){ | ||
67 | + //报警 | ||
68 | + alarmMsgService.sendSms("service_exception","gateway流量获取为空,influxdb :"+influxdbName,mobile); | ||
69 | + return ; | ||
70 | + } | ||
71 | + | ||
72 | + Double meanValueClose=0d; | ||
73 | + List<List<Object>> valuesList=QueryResultUtil.getValues(queryResultClose); | ||
74 | + if(!CollectionUtils.isEmpty(valuesList)){ | ||
75 | + for(List<Object> values:valuesList){ | ||
76 | + meanValueClose=(Double)values.get(1); | ||
77 | + } | ||
78 | + } | ||
79 | + | ||
80 | + Double meanValueFurther=0d; | ||
81 | + valuesList=QueryResultUtil.getValues(queryResultFurther); | ||
82 | + if(!CollectionUtils.isEmpty(valuesList)){ | ||
83 | + for(List<Object> values:valuesList){ | ||
84 | + meanValueFurther=(Double)values.get(1); | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + logger.info("GatewayMonitorTask influx is {} ,meanValueClose is {} , meanValueFurther is {}" ,influxdbName ,meanValueClose ,meanValueFurther); | ||
89 | + | ||
90 | + if(meanValueFurther>0&&meanValueClose==0){ | ||
91 | + //报警 | ||
92 | + alarmMsgService.sendSms("service_exception","gateway流量变化异常,最近2分钟均值的0,influxdb :"+influxdbName,mobile); | ||
93 | + return ; | ||
94 | + }else if(meanValueFurther==0&&meanValueClose==0){ | ||
95 | + //不报警 | ||
96 | + return ; | ||
97 | + }else{ | ||
98 | + //都大于零,比较变化幅度的绝对值和相对值 | ||
99 | + Double abs=Math.abs(meanValueFurther-meanValueClose); | ||
100 | + Double compareAbs=Math.abs((meanValueFurther-meanValueClose)/meanValueFurther) ; | ||
101 | + if(abs>100 && compareAbs>0.3){ | ||
102 | + String change="下降"; | ||
103 | + if(meanValueClose>meanValueFurther){ | ||
104 | + change="上升"; | ||
105 | + } | ||
106 | + //报警 | ||
107 | + alarmMsgService.sendSms("service_exception","gateway流量变化异常,最近2分钟"+change+" "+df.format(abs)+ ",变化率 "+df.format(compareAbs*100)+"%, influxdb :"+influxdbName,mobile); | ||
108 | + return ; | ||
109 | + } | ||
110 | + } | ||
111 | + } | ||
112 | +} |
@@ -35,6 +35,9 @@ cron_task_alarm_voice=0 0/5 * * * ? | @@ -35,6 +35,9 @@ cron_task_alarm_voice=0 0/5 * * * ? | ||
35 | 35 | ||
36 | cron_task_aplipay_voice=0 0/1 * * * ? | 36 | cron_task_aplipay_voice=0 0/1 * * * ? |
37 | 37 | ||
38 | +cron_task_gateway_monitor_aws=0 0/2 * * * ? | ||
39 | +cron_task_gateway_monitor_qcloud=1 0/2 * * * ? | ||
40 | + | ||
38 | cron_task_device_active=0 0/5 * * * ? | 41 | cron_task_device_active=0 0/5 * * * ? |
39 | device_active_period=60 | 42 | device_active_period=60 |
40 | 43 |
@@ -33,6 +33,9 @@ cron_task_alarm_voice=0 0/1 * * * ? | @@ -33,6 +33,9 @@ cron_task_alarm_voice=0 0/1 * * * ? | ||
33 | 33 | ||
34 | cron_task_aplipay_voice=0 0/1 * * * ? | 34 | cron_task_aplipay_voice=0 0/1 * * * ? |
35 | 35 | ||
36 | +cron_task_gateway_monitor_aws=0 0/2 * * * ? | ||
37 | +cron_task_gateway_monitor_qcloud=1 0/2 * * * ? | ||
38 | + | ||
36 | cron_task_device_active=0 0/5 * * * ? | 39 | cron_task_device_active=0 0/5 * * * ? |
37 | device_active_period=60 | 40 | device_active_period=60 |
38 | 41 |
@@ -42,6 +42,9 @@ cron_task_alarm_voice=0 0 0 * * ? | @@ -42,6 +42,9 @@ cron_task_alarm_voice=0 0 0 * * ? | ||
42 | 42 | ||
43 | cron_task_aplipay_voice=0 0 0 * * ? | 43 | cron_task_aplipay_voice=0 0 0 * * ? |
44 | 44 | ||
45 | +cron_task_gateway_monitor_aws=0 0 0 * * ? | ||
46 | +cron_task_gateway_monitor_qcloud=0 0 0 * * ? | ||
47 | + | ||
45 | cron_task_device_active=0 0 0 * * ? | 48 | cron_task_device_active=0 0 0 * * ? |
46 | device_active_period=60 | 49 | device_active_period=60 |
47 | 50 |
-
Please register or login to post a comment