예제 #1
0
  @Override
  public StateReport queryDailyReport(String domain, Date start, Date end) {
    StateReportMerger merger = new StateReportMerger(new StateReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = StateAnalyzer.ID;

    for (; startTime < endTime; startTime = startTime + TimeUtil.ONE_DAY) {
      try {
        DailyReport report =
            m_dailyReportDao.findByDomainNamePeriod(
                domain, name, new Date(startTime), DailyReportEntity.READSET_FULL);
        String xml = report.getContent();

        if (xml != null && xml.length() > 0) {
          StateReport reportModel =
              com.dianping.cat.consumer.state.model.transform.DefaultSaxParser.parse(xml);
          reportModel.accept(merger);
        } else {
          StateReport reportModel = queryFromDailyBinary(report.getId(), domain);

          reportModel.accept(merger);
        }
      } catch (DalNotFoundException e) {
        // ignore
      } catch (Exception e) {
        Cat.logError(e);
      }
    }
    StateReport stateReport = merger.getStateReport();

    stateReport.setStartTime(start);
    stateReport.setEndTime(end);
    return stateReport;
  }
예제 #2
0
  @Override
  public StateReport queryHourlyReport(String domain, Date start, Date end) {
    StateReportMerger merger = new StateReportMerger(new StateReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = StateAnalyzer.ID;

    for (; startTime < endTime; startTime = startTime + TimeUtil.ONE_HOUR) {
      List<HourlyReport> reports = null;
      try {
        reports =
            m_hourlyReportDao.findAllByDomainNamePeriod(
                new Date(startTime), domain, name, HourlyReportEntity.READSET_FULL);
      } catch (DalException e) {
        Cat.logError(e);
      }
      if (reports != null) {
        for (HourlyReport report : reports) {
          String xml = report.getContent();

          try {
            if (xml != null && xml.length() > 0) { // for old xml storage
              StateReport reportModel =
                  com.dianping.cat.consumer.state.model.transform.DefaultSaxParser.parse(xml);
              reportModel.accept(merger);
            } else { // for new binary storage, binary is same to report id
              StateReport reportModel = queryFromHourlyBinary(report.getId(), domain);

              reportModel.accept(merger);
            }
          } catch (DalNotFoundException e) {
            // ignore
          } catch (Exception e) {
            Cat.logError(e);
          }
        }
      }
    }
    StateReport stateReport = merger.getStateReport();

    stateReport.setStartTime(start);
    stateReport.setEndTime(new Date(end.getTime() - 1));
    return stateReport;
  }