Ejemplo n.º 1
0
    private void reload() {
      Date start = TimeUtil.getCurrentWeek();
      Date end = TimeUtil.getCurrentDay();
      Set<String> domains = m_hourReportService.queryAllDomainNames(start, end, "transaction");

      for (String domain : domains) {
        TransactionReport transactionReport =
            m_dailyReportService.queryTransactionReport(domain, start, end);
        new TransactionReportUrlFilter().visitTransactionReport(transactionReport);

        m_transactionReports.put(domain, transactionReport);
        m_eventReports.put(domain, m_dailyReportService.queryEventReport(domain, start, end));
        m_problemReports.put(domain, m_dailyReportService.queryProblemReport(domain, start, end));
        m_crossReports.put(domain, m_dailyReportService.queryCrossReport(domain, start, end));
        MatrixReport matrixReport = m_dailyReportService.queryMatrixReport(domain, start, end);

        m_matrixReports.put(domain, matrixReport);
        new MatrixReportFilter().visitMatrixReport(matrixReport);
        m_sqlReports.put(domain, m_dailyReportService.querySqlReport(domain, start, end));
      }
      String cat = "Cat";

      m_stateReports.put(cat, m_dailyReportService.queryStateReport(cat, start, end));
      m_end = end.getTime();
    }
Ejemplo n.º 2
0
  public void insert() throws Exception {
    String xml = Files.forIO().readFrom(new File("text.xml"), "utf-8");
    System.out.println(xml.length());
    try {
      Report r = m_reportDao.createLocal();
      // String xml = new TransactionReportUrlFilter().buildXml(report);
      String domain = "CatTest";

      r.setName("transaction");
      r.setDomain(domain);
      r.setPeriod(TimeUtil.getCurrentDay());
      r.setIp("127.0.0.1");
      r.setType(1);
      r.setContent(xml);
      System.out.println("insertBefore");
      m_reportDao.insert(r);

      System.out.println("insert");
    } catch (Throwable e) {
      System.out.println(e);
      Cat.getProducer().logError(e);
    }

    List<Report> temp =
        m_reportDao.findAllByPeriodDomainName(
            TimeUtil.getCurrentDay(), "CatTest", "transaction", ReportEntity.READSET_FULL);
    System.out.println(temp.size());
    for (Report re : temp) {
      TransactionReport report = DefaultSaxParser.parse(re.getContent());
      new Vistor().visitTransactionReport(report);
    }
  }
Ejemplo n.º 3
0
  @Test
  public void builderData() throws IOException {
    Date start = TimeUtil.getLastMonth();
    Date end = TimeUtil.getCurrentMonth();

    List<String> domains = queryAllDomain(start, end);

    int day = 31;
    for (int i = 0; i < day; i++) {
      Date date = new Date(start.getTime() + i * TimeUtil.ONE_DAY);
      System.out.println("process day " + date);
      processOneDay(date, domains);
    }

    System.out.print("项目名称" + "\t");
    System.out.print("部署机器" + "\t");
    System.out.print("平均负载" + "\t");
    System.out.println("最大负载" + "\t");

    for (Entry<String, MonthDomain> entry : m_indicators.entrySet()) {
      MonthDomain monthInfo = entry.getValue();

      System.out.println(entry.getKey() + "\t" + monthInfo);
    }
  }
Ejemplo n.º 4
0
    @Override
    public void run() {
      boolean active = true;

      while (active) {
        Date date = TimeUtil.getCurrentDay();
        long time = date.getTime();

        if (time > m_end) {
          Transaction t = Cat.newTransaction("ReportReload", "Week");
          try {
            reload();
            t.setStatus(Transaction.SUCCESS);
          } catch (Exception e) {
            Cat.logError(e);
            t.setStatus(e);
          } finally {
            t.complete();
          }
        }
        try {
          Thread.sleep(60 * 60 * 1000);
        } catch (InterruptedException e) {
          active = false;
        }
      }
    }
Ejemplo n.º 5
0
  @Test
  public void testDataBaseOnLine() throws Exception {
    byte[] data = Files.forIO().readFrom(new File("report-transaction"));
    String all = new String(data, 1946326, 11610469 - 1946326);

    String shopWeb = all;

    System.out.println(shopWeb.substring(7, 100));
    int length = shopWeb.length();
    System.out.println(shopWeb.substring(length - 100, length));

    System.out.println("Old Length" + shopWeb.length());
    String domain = System.currentTimeMillis() + "";
    try {
      Report r = m_reportDao.createLocal();
      // String xml = new TransactionReportUrlFilter().buildXml(report);
      r.setName("transaction");
      r.setDomain(domain);
      r.setPeriod(TimeUtil.getCurrentDay());
      r.setIp("127.0.0.1");
      r.setType(1);
      r.setContent(shopWeb);
      m_reportDao.insert(r);

    } catch (Throwable e) {
      System.out.println(e);
      Cat.getProducer().logError(e);
    }

    Files.forIO().writeTo(new File("sfs.xml"), shopWeb.substring(7, shopWeb.length()).trim());
    TransactionReport report1 = DefaultSaxParser.parse(shopWeb);
    System.out.println(">>>>>>>" + report1.getMachines().size());
    List<Report> temp =
        m_reportDao.findAllByPeriodDomainName(
            TimeUtil.getCurrentDay(), domain, "transaction", ReportEntity.READSET_FULL);
    System.out.println("temp size" + temp.size());
    for (Report re : temp) {
      String content = re.getContent();
      System.out.println("New Length:" + content.length());

      System.out.println(content.substring(0, 100));
      System.out.println(content.substring(length - 100, length));

      TransactionReport report = DefaultSaxParser.parse(content);
      new Vistor().visitTransactionReport(report);
    }
  }
Ejemplo n.º 6
0
  private Map<String, double[]> queryMetricValueByDate(String productLine, long start) {
    MetricReport metricReport =
        m_metricReportService.queryMetricReport(productLine, new Date(start));
    List<String> domains = m_productLineConfigManager.queryDomainsByProductLine(productLine);
    List<MetricItemConfig> metricConfigs = m_metricConfigManager.queryMetricItemConfigs(domains);

    Collections.sort(
        metricConfigs,
        new Comparator<MetricItemConfig>() {
          @Override
          public int compare(MetricItemConfig o1, MetricItemConfig o2) {
            return (int) (o1.getViewOrder() * 100 - o2.getViewOrder() * 100);
          }
        });
    Map<String, double[]> currentValues = buildGraphData(metricReport, metricConfigs);
    double sum = 0;

    for (Entry<String, double[]> entry : currentValues.entrySet()) {
      double[] value = entry.getValue();
      int length = value.length;

      for (int i = 0; i < length; i++) {
        sum = sum + value[i];
      }
    }
    // if current report is not exist, use last day value replace it.
    if (sum <= 0 && start < TimeUtil.getCurrentHour().getTime()) {
      MetricReport lastMetricReport =
          m_metricReportService.queryMetricReport(productLine, new Date(start - TimeUtil.ONE_DAY));
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:ss");

      m_logger.error(
          "Replace error value, Metric report is not exsit, productLine:"
              + productLine
              + " ,date:"
              + sdf.format(new Date(start)));
      return buildGraphData(lastMetricReport, metricConfigs);
    }
    return currentValues;
  }
Ejemplo n.º 7
0
  private boolean isCurrentMode(Date date) {
    Date current = TimeUtil.getCurrentHour();

    return current.getTime() == date.getTime() - TimeUtil.ONE_HOUR;
  }