Authored by wangning

update

@@ -23,6 +23,8 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc @@ -23,6 +23,8 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
23 23
24 private String contextFilter = "(context = 'gateway' or context = 'order' or context = 'promotion' or context = 'product' or context = 'message' or context = 'sns' or context = 'users' or context = 'resources' or context = 'brower')"; 24 private String contextFilter = "(context = 'gateway' or context = 'order' or context = 'promotion' or context = 'product' or context = 'message' or context = 'sns' or context = 'users' or context = 'resources' or context = 'brower')";
25 25
  26 + private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
  27 +
26 //根据context获取总响应次数和平均耗时 28 //根据context获取总响应次数和平均耗时
27 @Override 29 @Override
28 public Map<String,NewJavaApiInfoRep> getBaseDataByContext(NewJavaApiInfoReq req) { 30 public Map<String,NewJavaApiInfoRep> getBaseDataByContext(NewJavaApiInfoReq req) {
@@ -397,7 +399,13 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc @@ -397,7 +399,13 @@ public class ServiceAccessMapperImpl extends InfluxDBQuery implements ServiceAcc
397 399
398 @Override 400 @Override
399 public List<Map> getAlarmData(Integer costThreshold){ 401 public List<Map> getAlarmData(Integer costThreshold){
400 - String sql = String.format("select count(cost),mean(cost) from service_access where %s and time > now() - 10s group by hostAddress,context;select count(cost) from service_access where %s and time > now() - 10s and cost > %d group by hostAddress,context",contextFilter,contextFilter,costThreshold); 402 + DateTime endDateTime = DateTime.now(DateTimeZone.UTC);
  403 + DateTime startDateTime = endDateTime.minusSeconds(10);
  404 + String startDateStr = startDateTime.toString(DATE_TIME_FORMAT);
  405 + String endDateStr = endDateTime.toString(DATE_TIME_FORMAT);
  406 + String sql1 = String.format("select count(cost),mean(cost) from service_access where %s and time > '%s' and time < '%s' group by hostAddress,context;",contextFilter,startDateStr,endDateStr);
  407 + String sql2 = String.format("select count(cost) from service_access where %s and time > '%s' and time < '%s' and cost > %d group by hostAddress,context",contextFilter,startDateStr,endDateStr,costThreshold);
  408 + String sql = sql1 + sql2;
401 List<Map> list = new ArrayList<>(); 409 List<Map> list = new ArrayList<>();
402 list.addAll(getAlarmData(InfluxDBContants.AWS,sql)); 410 list.addAll(getAlarmData(InfluxDBContants.AWS,sql));
403 list.addAll(getAlarmData(InfluxDBContants.Q_CLOUD,sql)); 411 list.addAll(getAlarmData(InfluxDBContants.Q_CLOUD,sql));