Example #1
0
  @Override
  public StateReport makeReport(String domain, Date start, Date end) {
    StateReport report = new StateReport(domain);

    report.setStartTime(start);
    report.setEndTime(end);
    return report;
  }
Example #2
0
  @Override
  public StateReport makeReport(String domain, long startTime, long duration) {
    StateReport report = new StateReport(domain);

    report.setStartTime(new Date(startTime));
    report.setEndTime(new Date(startTime + duration - 1));

    return report;
  }
Example #3
0
  @Override
  public boolean createHourlyTask(StateReport report) {
    Date startTime = report.getStartTime();
    String domain = report.getDomain();

    m_taskManager.createTask(startTime, domain, Constants.REPORT_SERVICE, TaskProlicy.ALL);
    m_taskManager.createTask(startTime, domain, Constants.REPORT_BUG, TaskProlicy.ALL);
    m_taskManager.createTask(startTime, domain, Constants.REPORT_HEAVY, TaskProlicy.ALL);
    m_taskManager.createTask(startTime, domain, Constants.REPORT_UTILIZATION, TaskProlicy.ALL);
    return m_taskManager.createTask(
        startTime, domain, StateAnalyzer.ID, TaskProlicy.ALL_EXCLUED_HOURLY);
  }
Example #4
0
  @Override
  public StateReport mergeReport(StateReport old, StateReport other) {
    StateReportMerger merger = new StateReportMerger(old);

    other.accept(merger);
    return old;
  }
Example #5
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;
  }
Example #6
0
  private double[] getDataFromHourlySummary(
      List<StateReport> reports, long start, int size, String key, String ip) {
    double[] result = new double[size];

    for (StateReport report : reports) {
      Date startTime = report.getStartTime();
      StateShow show = new StateShow(ip);

      show.visitStateReport(report);
      int i = (int) ((startTime.getTime() - start) / TimeUtil.ONE_HOUR);

      if (key.equalsIgnoreCase("total")) {
        result[i] = show.getTotal().getTotal();
      } else if (key.equalsIgnoreCase("totalLoss")) {
        result[i] = show.getTotal().getTotalLoss();
      } else if (key.equalsIgnoreCase("avgTps")) {
        result[i] = show.getTotal().getAvgTps();
      } else if (key.equalsIgnoreCase("maxTps")) {
        result[i] = show.getTotal().getMaxTps();
      } else if (key.equalsIgnoreCase("dump")) {
        result[i] = show.getTotal().getDump();
      } else if (key.equalsIgnoreCase("dumpLoss")) {
        result[i] = show.getTotal().getDumpLoss();
      } else if (key.equalsIgnoreCase("pigeonTimeError")) {
        result[i] = show.getTotal().getPigeonTimeError();
      } else if (key.equalsIgnoreCase("networkTimeError")) {
        result[i] = show.getTotal().getNetworkTimeError();
      } else if (key.equalsIgnoreCase("blockTotal")) {
        result[i] = show.getTotal().getBlockTotal();
      } else if (key.equalsIgnoreCase("blockLoss")) {
        result[i] = show.getTotal().getBlockLoss();
      } else if (key.equalsIgnoreCase("blockTime")) {
        result[i] = show.getTotal().getBlockTime() * 1.0 / 60 / 1000;
      } else if (key.equalsIgnoreCase("size")) {
        result[i] = show.getTotal().getSize() / 1024 / 1024;
      } else if (key.equalsIgnoreCase("delayAvg")) {
        if (show.getTotal().getDelayCount() > 0) {
          result[i] = show.getTotal().getDelaySum() / show.getTotal().getDelayCount();
        }
      }
    }
    return result;
  }
Example #7
0
  @Override
  protected void process(MessageTree tree) {
    StateReport report = m_reportManager.getHourlyReport(getStartTime(), Constants.CAT, true);
    String domain = tree.getDomain();
    String ip = tree.getIpAddress();
    Machine machine =
        report.findOrCreateMachine(NetworkInterfaceManager.INSTANCE.getLocalHostAddress());

    machine.findOrCreateProcessDomain(domain).addIp(ip);
    if (m_serverConfigManager.validateDomain(domain)) {
      if (!m_domainManager.containsDomainInCat(domain)) {
        boolean insert = m_domainManager.insertDomain(domain);

        if (!insert) {
          m_logger.warn(String.format("Error when insert domain %s info", domain));
        }
      }
      Hostinfo info = m_domainManager.queryHostInfoByIp(ip);

      if (info == null) {
        m_domainManager.insert(domain, ip);
      } else {
        String oldDomain = info.getDomain();

        if (!oldDomain.equals(domain) && !oldDomain.equals(Constants.CAT)) {
          // only work on online environment
          long current = System.currentTimeMillis();
          Date lastModifiedDate = info.getLastModifiedDate();

          if (lastModifiedDate != null && (current - lastModifiedDate.getTime()) > ONE_HOUR) {
            m_domainManager.update(info.getId(), domain, ip);
            m_logger.info(
                String.format("old domain is %s , change ip %s to %s", oldDomain, ip, domain));
          }
        }
      }
    }
  }
Example #8
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;
  }
Example #9
0
  @Override
  public StateReport getReport(String domain) {
    StateReport report = new StateReport(Constants.CAT);

    report.setStartTime(new Date(m_startTime));
    report.setEndTime(new Date(m_startTime + MINUTE * 60 - 1));

    Machine machine = buildStateInfo(report.findOrCreateMachine(m_ip));
    StateReport stateReport = m_reportManager.getHourlyReport(getStartTime(), Constants.CAT, true);
    Map<String, ProcessDomain> processDomains =
        stateReport.findOrCreateMachine(m_ip).getProcessDomains();

    for (Map.Entry<String, ProcessDomain> entry : machine.getProcessDomains().entrySet()) {
      ProcessDomain processDomain = processDomains.get(entry.getKey());

      if (processDomain != null) {
        entry.getValue().getIps().addAll(processDomain.getIps());
      }
    }
    return report;
  }
Example #10
0
 @Override
 public String getDomain(StateReport report) {
   return report.getDomain();
 }
Example #11
0
 @Override
 public String buildXml(StateReport report) {
   return report.toString();
 }