|
|
package com.monitor.other.task.someTask;
|
|
|
|
|
|
import com.monitor.common.config.SnsMobileConfig;
|
|
|
import com.monitor.common.service.AlarmMsgService;
|
|
|
import com.monitor.influxdb.contants.InfluxDBContants;
|
|
|
import com.monitor.influxdb.mapper.GatewayAccessAllMapper;
|
|
|
import com.monitor.influxdb.util.QueryResultUtil;
|
|
|
import com.monitor.other.dockermonitor.task.DockerMonitorTask;
|
|
|
import com.util.GetUsersInfoUtil;
|
|
|
import org.influxdb.dto.QueryResult;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Created by craig.qin on 2018/4/3.
|
|
|
* gateway流量有巨大变化的时候,告警
|
|
|
*/
|
|
|
@Component
|
|
|
public class GatewayMonitorTask {
|
|
|
public static final Logger logger = LoggerFactory.getLogger(GatewayMonitorTask.class);
|
|
|
DecimalFormat df = new DecimalFormat("######0.00");
|
|
|
|
|
|
@Autowired
|
|
|
private GatewayAccessAllMapper gatewayAccessAllMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SnsMobileConfig snsMobileConfig;
|
|
|
|
|
|
@Autowired
|
|
|
private AlarmMsgService alarmMsgService;
|
|
|
|
|
|
//当前环境
|
|
|
@Value("${system.envi}")
|
|
|
private String env;
|
|
|
|
|
|
@Scheduled(cron = "${cron_task_gateway_monitor_aws}")
|
|
|
public void alarmGatewayMonitor_aws() {
|
|
|
if("test1".equals(env)||"test".equals(env)){
|
|
|
return ;
|
|
|
}
|
|
|
alarm(InfluxDBContants.AWS);
|
|
|
}
|
|
|
|
|
|
|
|
|
//@Scheduled(cron = "${cron_task_gateway_monitor_qcloud}")
|
|
|
public void alarmGatewayMonitor_qcloud() {
|
|
|
if("test1".equals(env)||"test".equals(env)){
|
|
|
return ;
|
|
|
}
|
|
|
alarm(InfluxDBContants.Q_CLOUD);
|
|
|
}
|
|
|
|
|
|
private void alarm(String influxdbName){
|
|
|
String mobile=snsMobileConfig.getTestMobile();
|
|
|
QueryResult queryResultFurther = gatewayAccessAllMapper.selectMeanValue(influxdbName,4,2);
|
|
|
QueryResult queryResultClose = gatewayAccessAllMapper.selectMeanValue(influxdbName,2,0);
|
|
|
if(queryResultClose==null||queryResultFurther==null){
|
|
|
//报警
|
|
|
alarmMsgService.sendSms("service_exception","gateway流量获取为空,influxdb :"+influxdbName,mobile);
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
Double meanValueClose=0d;
|
|
|
List<List<Object>> valuesList=QueryResultUtil.getValues(queryResultClose);
|
|
|
if(!CollectionUtils.isEmpty(valuesList)){
|
|
|
for(List<Object> values:valuesList){
|
|
|
meanValueClose=(Double)values.get(1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Double meanValueFurther=0d;
|
|
|
valuesList=QueryResultUtil.getValues(queryResultFurther);
|
|
|
if(!CollectionUtils.isEmpty(valuesList)){
|
|
|
for(List<Object> values:valuesList){
|
|
|
meanValueFurther=(Double)values.get(1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
logger.info("GatewayMonitorTask influx is {} ,meanValueClose is {} , meanValueFurther is {}" ,influxdbName ,meanValueClose ,meanValueFurther);
|
|
|
|
|
|
if(meanValueFurther>0&&meanValueClose==0){
|
|
|
//报警
|
|
|
alarmMsgService.sendSms("service_exception","gateway流量变化异常,最近2分钟均值的0,influxdb :"+influxdbName,mobile);
|
|
|
return ;
|
|
|
}else if(meanValueFurther==0&&meanValueClose==0){
|
|
|
//不报警
|
|
|
return ;
|
|
|
}else{
|
|
|
//都大于零,比较变化幅度的绝对值和相对值
|
|
|
Double abs=Math.abs(meanValueFurther-meanValueClose);
|
|
|
Double compareAbs=Math.abs((meanValueFurther-meanValueClose)/meanValueFurther) ;
|
|
|
if(abs>200 || compareAbs>0.3){
|
|
|
//报警
|
|
|
alarmMsgService.sendSms("service_exception","gateway流量变化异常,最近2分钟均值变化值 "+abs+ ",变化率 "+df.format(compareAbs*100)+"% influxdb :"+influxdbName,mobile);
|
|
|
return ;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|