Authored by wangning

发送短信增加请求总次数限制

... ... @@ -24,6 +24,9 @@ public class SnsMobileConfig {
@Value("${java_service_alarm_cost_threshold}")
private Integer javaServiceCostThreshold;
@Value("${java_service_alarm_count_threshold}")
private Integer javaServiceCountThreshold;
public String getBaseMobile() {
return baseMobile;
}
... ... @@ -64,4 +67,12 @@ public class SnsMobileConfig {
public void setJavaServiceCostThreshold(Integer javaServiceCostThreshold) {
this.javaServiceCostThreshold = javaServiceCostThreshold;
}
public Integer getJavaServiceCountThreshold() {
return javaServiceCountThreshold;
}
public void setJavaServiceCountThreshold(Integer javaServiceCountThreshold) {
this.javaServiceCountThreshold = javaServiceCountThreshold;
}
}
... ...
... ... @@ -32,5 +32,5 @@ public interface ServiceAccessMapper {
Map<String,Integer> getTimeoutCountByContextAndApiName(NewJavaApiInfoReq req);
List<Map> getAlarmData(Integer costThreshold);
List<Map> getAlarmData(Integer costThreshold,Integer countThreshold);
}
... ...
... ... @@ -382,7 +382,7 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
}
@Override
public List<Map> getAlarmData(Integer costThreshold){
public List<Map> getAlarmData(Integer costThreshold,Integer countThreshold){
DateTime endDateTime = DateTime.now(DateTimeZone.UTC).minusSeconds(10);
DateTime startDateTime = endDateTime.minusSeconds(10);
String startDateStr = startDateTime.toString(DATE_TIME_FORMAT);
... ... @@ -392,12 +392,12 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
String sql = sql1 + sql2;
log.info("getAlarmData sql is " + sql);
List<Map> list = new ArrayList<>();
list.addAll(getAlarmData(InfluxDBContants.AWS,sql));
list.addAll(getAlarmData(InfluxDBContants.Q_CLOUD,sql));
list.addAll(getAlarmData(InfluxDBContants.AWS,sql,countThreshold));
list.addAll(getAlarmData(InfluxDBContants.Q_CLOUD,sql,countThreshold));
return list;
}
private List<Map> getAlarmData(String source,String sql){
private List<Map> getAlarmData(String source,String sql,Integer countThreshold){
List<Map> returnList = new ArrayList<>();
QueryResult queryResult = query(source, sql, InfluxDBContants.YOHO_EVENT);
... ... @@ -425,7 +425,7 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
Double mean = (Double)series2.getValues().get(0).get(2);
Double ratio = timeoutCount / totalCount;
log.info("hostAddress:" + hostAddress + ",serviceName:" + serviceName + ",timeoutCount:" + timeoutCount + ",totalCount:" + totalCount + ",ratio:" + ratio + ",mean:" + mean);
if(ratio >= 0.95){
if((ratio >= 0.95) && (totalCount > countThreshold)){
Map map = new HashMap();
map.put("hostAddress",hostAddress);
map.put("serviceName",serviceName);
... ...
... ... @@ -376,9 +376,15 @@ public class NewJavaApiInfoServiceImpl implements NewJavaApiInfoService {
if(costThreshold == null){
costThreshold = 300;
}
Integer countThreshold = snsMobileConfig.getJavaServiceCountThreshold();
if(countThreshold == null){
countThreshold = 50;
}
String nowString = DateTime.now().minusSeconds(10).toString("yyyy-MM-dd HH:mm:ss");
log.info("sendAlarmMsg nowString is :" + nowString + ",costThreshold is " + costThreshold);
List<Map> list = serviceAccessMapper.getAlarmData(costThreshold);
log.info("sendAlarmMsg nowString is :" + nowString + ",costThreshold is " + costThreshold + ",countThreshold is " + countThreshold);
List<Map> list = serviceAccessMapper.getAlarmData(costThreshold,countThreshold);
//获取cpu、内存、带宽使用情况
Map vmInfoMap = vmInfoMapper.getVMInfo();
String costMsgContentTemplate = "时间:%s,服务名:%s,IP:%s,超过%dms的请求占比%s,平均耗时:%dms,CPU使用率:%s,可用内存/总内存(MB):%s";
... ...
... ... @@ -18,5 +18,6 @@ redis_exception_mobile=13515100825,18751986615,18652008443,18502542319
java_service_alarm_mobile=18751986615,18652008443,18502542319
java_service_alarm_flag=true
java_service_alarm_cost_threshold=300
java_service_alarm_count_threshold=50
... ...
... ... @@ -22,5 +22,6 @@ redis_exception_mobile=15905144483
java_service_alarm_mobile=18614066537
java_service_alarm_flag=true
java_service_alarm_cost_threshold=150
java_service_alarm_count_threshold=50
... ...