コード例 #1
0
  private void buildHourlyTaskInternal(Date period, Set<String> productLineSet) {
    MetricReportForABTestVisitor visitor = new MetricReportForABTestVisitor();

    for (String productLine : productLineSet) {
      MetricReport metricReport =
          m_reportService.queryMetricReport(
              productLine, period, new Date(period.getTime() + TimeUtil.ONE_HOUR));

      metricReport.accept(visitor);
    }

    Map<Integer, AbtestReport> result = visitor.getReportMap();

    for (AbtestReport report : result.values()) {
      if (report.getRunId() != -1) {
        com.dianping.cat.home.dal.abtest.AbtestReport _report =
            new com.dianping.cat.home.dal.abtest.AbtestReport();

        _report.setRunId(report.getRunId());
        _report.setPeriod(period);
        _report.setContent(report.toString());

        try {
          m_abtestReportDao.insert(_report);
        } catch (DalException e) {
          Cat.logError(e);
        }
      }
    }
  }
コード例 #2
0
  @Override
  public void visitMetricReport(MetricReport metricReport) {
    m_startDate = metricReport.getStartTime();
    m_endDate = metricReport.getEndTime();

    super.visitMetricReport(metricReport);
  }
コード例 #3
0
ファイル: NetGraphManager.java プロジェクト: jinbochen/cat
    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);
      }
    }
コード例 #4
0
ファイル: BaseAlert.java プロジェクト: nanin/cat
  protected void processProductLine(ProductLine productLine) {
    long current = (System.currentTimeMillis()) / 1000 / 60;
    int minute = (int) (current % (60)) - DATA_AREADY_MINUTE;
    String product = productLine.getId();
    MetricReport report = fetchMetricReport(product, ModelPeriod.CURRENT);

    for (Entry<String, MetricItem> entry : report.getMetricItems().entrySet()) {
      try {
        processMetricItem(minute, productLine, entry.getKey());
      } catch (Exception e) {
        Cat.logError(e);
      }
    }
  }
コード例 #5
0
  @Test
  public void test() throws Exception {
    String xml =
        Files.forIO().readFrom(getClass().getResourceAsStream("metricReport.xml"), "utf-8");

    MetricReport metricReport = DefaultSaxParser.parse(xml);

    MetricReportForABTestVisitor visitor = new MetricReportForABTestVisitor();

    metricReport.accept(visitor);

    Map<Integer, AbtestReport> result = visitor.getReportMap();

    Calendar calendar = Calendar.getInstance();
    Date now = new Date();
    calendar.setTime(now);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.roll(Calendar.DAY_OF_MONTH, -14);

    for (AbtestReport ar : result.values()) {
      if (ar.getRunId() != -1) {
        System.out.println(ar.toString());
        for (int i = 0; i < 14; i++) {
          for (int j = 0; j < 24; j++) {
            Date begin = calendar.getTime();

            calendar.roll(Calendar.HOUR_OF_DAY, true);
            Date end = calendar.getTime();

            System.out.println("Import new report for " + begin);
            ar.setStartTime(begin);
            ar.setEndTime(end);

            com.dianping.cat.home.dal.abtest.AbtestReport report =
                new com.dianping.cat.home.dal.abtest.AbtestReport();
            report.setPeriod(begin);
            report.setRunId(ar.getRunId());
            report.setContent(ar.toString());

            m_abtestReportDao.insert(report);
          }
          calendar.roll(Calendar.DAY_OF_MONTH, true);
        }
      }
    }
  }
コード例 #6
0
ファイル: BaseAlert.java プロジェクト: nanin/cat
  private double[] queryRealData(
      int start, int end, String metricKey, MetricReport report, MetricType type) {
    double[] all = new double[60];
    Map<Integer, Segment> map = report.findOrCreateMetricItem(metricKey).getSegments();

    for (Entry<Integer, Segment> entry : map.entrySet()) {
      Integer minute = entry.getKey();
      Segment seg = entry.getValue();

      if (type == MetricType.AVG) {
        all[minute] = seg.getAvg();
      } else if (type == MetricType.COUNT) {
        all[minute] = (double) seg.getCount();
      } else if (type == MetricType.SUM) {
        all[minute] = seg.getSum();
      }
    }
    int length = end - start + 1;
    double[] result = new double[length];
    System.arraycopy(all, start, result, 0, length);

    return result;
  }