コード例 #1
0
ファイル: ThresholdJudge.java プロジェクト: kevx/csp
 private String getSpecialMessage(KeyDefine define) {
   if (DiamondConstant.AtomInitialExceptionKeyName.equals(define.getKeyName())
       || DiamondConstant.ConfigExceptionKeyName.equals(define.getKeyName())) {
     return ",diamond推送tddl数据源出错";
   } else {
     return "";
   }
 }
コード例 #2
0
ファイル: ThresholdJudge.java プロジェクト: kevx/csp
  @Override
  public Result judge(KeyDefine define, AlarmContext context) {

    // 取得最近记录
    Map<Date, String> dataMap = context.getValueMap();
    // 降序排序时间
    List<Date> sortDateList = sortDateDesc(dataMap);
    if (sortDateList == null || sortDateList.size() == 0) {
      return null;
    }

    Date maxDate = sortDateList.get(0);
    Date secondDate = null;
    Date thrDate = null;
    if (sortDateList.size() > 2) {
      secondDate = sortDateList.get(1);
      thrDate = sortDateList.get(2);
    }
    List<RangeDefine> rangeList = define.getRangeList();

    for (RangeDefine range : rangeList) {

      if (maxDate != null) {
        String maxValue = dataMap.get(maxDate);
        if (maxValue != null) {
          try {
            int startTime = range.getStartTime();
            int endTime = range.getEndTime();
            int maxTime = parseDateToNumber(maxDate);

            if (maxTime > startTime && maxTime < endTime) {
              double greater = range.getGreaterthan();
              double less = range.getLessthan();
              if (Double.parseDouble(maxValue) > less && less != -1) {
                return new Result(
                    createMessage(KeyJudgeEnum.greaterTo, range, context.getKeyId())
                        + getSpecialMessage(define),
                    KeyJudgeEnum.greaterTo);
              }

              if (greater != -1
                  && secondDate != null
                  && thrDate != null) { // 主要是最近的一个记录可能在收集的时候,不是在一个时间点内全部取完整,所以使用第二个时间点这样能保证是完整的
                Double secondvalue = Double.parseDouble(dataMap.get(secondDate));
                Double thrValue = Double.parseDouble(dataMap.get(thrDate));
                if (thrValue < greater
                    && secondvalue < greater
                    && greater != -1
                    && Double.parseDouble(maxValue) < greater) {
                  return new Result(
                      createMessage(KeyJudgeEnum.lessTo, range, context.getKeyId())
                          + getSpecialMessage(define),
                      KeyJudgeEnum.lessTo);
                }
              }
            }
          } catch (Exception e) {
          }
        }
      }
    }
    return null;
  }