Example #1
0
    private void updateInterface(Interface inter, int minute) {
      String group = inter.getGroup();
      String domain = inter.getDomain();
      String key = inter.getKey();
      long period;

      minute -= DATA_DELAY_TIME;
      if (minute >= 0) {
        period = ModelPeriod.CURRENT.getStartTime();
      } else {
        period = ModelPeriod.LAST.getStartTime();
        minute += 60;
      }

      try {
        ModelRequest request = new ModelRequest(group, period);
        MetricReport report = m_service.invoke(request);

        if (report != null) {
          MetricItem inItem = report.findOrCreateMetricItem(domain + ":Metric:" + key + "-in");
          MetricItem outItem = report.findOrCreateMetricItem(domain + ":Metric:" + key + "-out");

          inter.setIn(inItem.findOrCreateSegment(minute).getSum() / 60 * 8);
          inter.setOut(outItem.findOrCreateSegment(minute).getSum() / 60 * 8);
        }
      } catch (Exception e) {
        Cat.logError(e);
      }
    }
Example #2
0
  protected MetricReport fetchMetricReport(String product, ModelPeriod period) {
    if (period == ModelPeriod.CURRENT) {
      MetricReport report = m_currentReports.get(product);

      if (report != null) {
        return report;
      } else {
        ModelRequest request =
            new ModelRequest(product, ModelPeriod.CURRENT.getStartTime())
                .setProperty("requireAll", "ture");

        report = m_service.invoke(request);
        if (report != null) {
          m_currentReports.put(product, report);
        }
        return report;
      }
    } else if (period == ModelPeriod.LAST) {
      MetricReport report = m_lastReports.get(product);

      if (report != null) {
        return report;
      } else {
        ModelRequest request =
            new ModelRequest(product, ModelPeriod.LAST.getStartTime())
                .setProperty("requireAll", "ture");

        report = m_service.invoke(request);
        if (report != null) {
          m_lastReports.put(product, report);
        }
        return report;
      }
    } else {
      throw new RuntimeException("internal error, this can't be reached.");
    }
  }
Example #3
0
  protected AlertResultEntity computeAlertInfo(
      int minute, String product, String metricKey, MetricType type) {
    double[] value = null;
    double[] baseline = null;
    List<Config> configs = m_ruleConfigManager.queryConfigs(product, metricKey, type);
    Pair<Integer, List<Condition>> resultPair = queryCheckMinuteAndConditions(configs);
    int maxMinute = resultPair.getKey();
    List<Condition> conditions = resultPair.getValue();

    if (minute >= maxMinute - 1) {
      MetricReport report = fetchMetricReport(product, ModelPeriod.CURRENT);

      if (report != null) {
        int start = minute + 1 - maxMinute;
        int end = minute;

        value = queryRealData(start, end, metricKey, report, type);
        baseline =
            queryBaseLine(
                start, end, metricKey, new Date(ModelPeriod.CURRENT.getStartTime()), type);

        return m_dataChecker.checkData(value, baseline, conditions);
      }
    } else if (minute < 0) {
      MetricReport lastReport = fetchMetricReport(product, ModelPeriod.LAST);

      if (lastReport != null) {
        int start = 60 + minute + 1 - (maxMinute);
        int end = 60 + minute;

        value = queryRealData(start, end, metricKey, lastReport, type);
        baseline =
            queryBaseLine(start, end, metricKey, new Date(ModelPeriod.LAST.getStartTime()), type);
        return m_dataChecker.checkData(value, baseline, conditions);
      }
    } else {
      MetricReport currentReport = fetchMetricReport(product, ModelPeriod.CURRENT);
      MetricReport lastReport = fetchMetricReport(product, ModelPeriod.LAST);

      if (currentReport != null && lastReport != null) {
        int currentStart = 0, currentEnd = minute;
        double[] currentValue =
            queryRealData(currentStart, currentEnd, metricKey, currentReport, type);
        double[] currentBaseline =
            queryBaseLine(
                currentStart,
                currentEnd,
                metricKey,
                new Date(ModelPeriod.CURRENT.getStartTime()),
                type);

        int lastStart = 60 + 1 - (maxMinute - minute);
        int lastEnd = 59;
        double[] lastValue = queryRealData(lastStart, lastEnd, metricKey, lastReport, type);
        double[] lastBaseline =
            queryBaseLine(
                lastStart, lastEnd, metricKey, new Date(ModelPeriod.LAST.getStartTime()), type);

        value = mergerArray(lastValue, currentValue);
        baseline = mergerArray(lastBaseline, currentBaseline);
        return m_dataChecker.checkData(value, baseline, conditions);
      }
    }
    return null;
  }