Example #1
0
  private TransactionName getTransactionName(Payload payload) {
    String domain = payload.getDomain();
    String type = payload.getType();
    String name = payload.getName();
    String ip = payload.getIpAddress();
    String ipAddress = payload.getIpAddress();
    String date = String.valueOf(payload.getDate());
    ModelRequest request =
        new ModelRequest(domain, payload.getPeriod()) //
            .setProperty("date", date) //
            .setProperty("type", payload.getType()) //
            .setProperty("name", payload.getName()) //
            .setProperty("ip", ipAddress);
    if (name == null || name.length() == 0) {
      request.setProperty("name", "*");
      request.setProperty("all", "true");
      name = CatString.ALL;
    }
    ModelResponse<TransactionReport> response = m_service.invoke(request);
    TransactionReport report = response.getModel();

    report = m_mergeManager.mergerAll(report, ipAddress, name);
    TransactionType t = report.getMachines().get(ip).findType(type);
    if (t != null) {
      TransactionName n = t.findName(name);
      if (n != null) {
        n.accept(m_computer);
      }
      return n;
    } else {
      return null;
    }
  }
Example #2
0
  private TransactionReport getHourlyReport(Payload payload) {
    String domain = payload.getDomain();
    String date = String.valueOf(payload.getDate());
    String ipAddress = payload.getIpAddress();
    ModelRequest request =
        new ModelRequest(domain, payload.getPeriod()) //
            .setProperty("date", date) //
            .setProperty("type", payload.getType()) //
            .setProperty("ip", ipAddress);

    if (m_service.isEligable(request)) {
      ModelResponse<TransactionReport> response = m_service.invoke(request);
      TransactionReport report = response.getModel();

      if (payload.getPeriod().isLast()) {
        Date start = new Date(payload.getDate());
        Date end = new Date(payload.getDate() + TimeUtil.ONE_HOUR);

        if (CatString.ALL.equals(domain)) {
          report = m_reportService.queryTransactionReport(domain, start, end);
        }
        Set<String> domains = m_reportService.queryAllDomainNames(start, end, "transaction");
        Set<String> domainNames = report.getDomainNames();

        domainNames.addAll(domains);
      }
      report = m_mergeManager.mergerAllIp(report, ipAddress);
      calculateTps(payload, report);
      return report;
    } else {
      throw new RuntimeException(
          "Internal error: no eligable transaction service registered for " + request + "!");
    }
  }
Example #3
0
  private TransactionReport getHourlyReport(Payload payload) {
    String domain = payload.getDomain();
    String ipAddress = payload.getIpAddress();
    ModelRequest request =
        new ModelRequest(domain, payload.getDate())
            .setProperty("type", payload.getType())
            .setProperty("ip", ipAddress);

    if (m_service.isEligable(request)) {
      ModelResponse<TransactionReport> response = m_service.invoke(request);
      TransactionReport report = response.getModel();

      if (payload.getPeriod().isLast()) {
        Date start = new Date(payload.getDate());
        Date end = new Date(payload.getDate() + TimeHelper.ONE_HOUR);

        if (Constants.ALL.equals(domain)) {
          report = m_reportService.queryTransactionReport(domain, start, end);
        }
        Set<String> domains =
            m_reportService.queryAllDomainNames(start, end, TransactionAnalyzer.ID);
        Set<String> domainNames = report.getDomainNames();

        domainNames.addAll(domains);
      }
      return report;
    } else {
      throw new RuntimeException(
          "Internal error: no eligable transaction service registered for " + request + "!");
    }
  }
Example #4
0
  public DisplayNames display(
      String sorted, String type, String ip, TransactionReport report, String queryName) {
    Map<String, TransactionType> types = report.getMachines().get(ip).getTypes();
    TransactionName all = new TransactionName("TOTAL");
    all.setTotalPercent(1);
    if (types != null) {
      TransactionType names = types.get(type);

      if (names != null) {
        for (Entry<String, TransactionName> entry : names.getNames().entrySet()) {
          String transTypeName = entry.getValue().getId();
          boolean isAdd =
              (queryName == null || queryName.length() == 0 || isFit(queryName, transTypeName));
          if (isAdd) {
            m_results.add(new TransactionNameModel(entry.getKey(), entry.getValue()));
            mergeName(all, entry.getValue());
          }
        }
      }
    }
    if (sorted == null) {
      sorted = "avg";
    }
    Collections.sort(m_results, new TransactionNameComparator(sorted));

    long total = all.getTotalCount();
    for (TransactionNameModel nameModel : m_results) {
      TransactionName transactionName = nameModel.getDetail();
      transactionName.setTotalPercent(transactionName.getTotalCount() / (double) total);
    }
    m_results.add(0, new TransactionNameModel("TOTAL", all));
    return this;
  }
Example #5
0
  private void buildTransactionNameGraph(
      Model model, TransactionReport report, String type, String name, String ip) {
    TransactionType t = report.findOrCreateMachine(ip).findOrCreateType(type);
    TransactionName transactionName = t.findOrCreateName(name);
    transformTo60MinuteData(transactionName);

    if (transactionName != null) {
      String graph1 =
          m_builder.build(
              new DurationPayload(
                  "Duration Distribution", "Duration (ms)", "Count", transactionName));
      String graph2 =
          m_builder.build(new HitPayload("Hits Over Time", "Time (min)", "Count", transactionName));
      String graph3 =
          m_builder.build(
              new AverageTimePayload(
                  "Average Duration Over Time",
                  "Time (min)",
                  "Average Duration (ms)",
                  transactionName));
      String graph4 =
          m_builder.build(
              new FailurePayload("Failures Over Time", "Time (min)", "Count", transactionName));

      model.setGraph1(graph1);
      model.setGraph2(graph2);
      model.setGraph3(graph3);
      model.setGraph4(graph4);
    }
  }
Example #6
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);
    }
  }
Example #7
0
  @Test
  public void testProcessTransaction() throws Exception {
    timestamp = System.currentTimeMillis() - System.currentTimeMillis() % (3600 * 1000);
    TransactionAnalyzer analyzer = lookup(TransactionAnalyzer.class);
    TransactionReport report = new TransactionReport("Test");

    for (int i = 1; i <= 1000; i++) {
      MessageTree tree = newMessageTree(i);
      DefaultTransaction t = new DefaultTransaction("A", "n" + i % 2, null);
      DefaultTransaction t2 = new DefaultTransaction("A-1", "n" + i % 3, null);

      if (i % 2 == 0) {
        t2.setStatus("ERROR");
      } else {
        t2.setStatus(Message.SUCCESS);
      }

      t2.complete();
      t2.setDurationInMillis(i);

      t.addChild(t2);

      if (i % 2 == 0) {
        t.setStatus("ERROR");
      } else {
        t.setStatus(Message.SUCCESS);
      }

      t.complete();
      t.setDurationInMillis(i * 2);
      t.setTimestamp(timestamp + 1000);
      t2.setTimestamp(timestamp + 2000);
      tree.setMessage(t);

      analyzer.processTransaction(report, tree, t);
    }

    report.accept(new StatisticsComputer());

    String json = new DefaultJsonBuilder().buildJson(report);
    String expected =
        Files.forIO()
            .readFrom(getClass().getResourceAsStream("TransactionAnalyzerTest.json"), "utf-8");

    Assert.assertEquals(expected.replace("\r", ""), json.replace("\r", ""));
  }
Example #8
0
  private TransactionReport filterReportByGroup(
      TransactionReport report, String domain, String group) {
    List<String> ips = m_configManager.queryIpByDomainAndGroup(domain, group);
    List<String> removes = new ArrayList<String>();

    for (Machine machine : report.getMachines().values()) {
      String ip = machine.getIp();

      if (!ips.contains(ip)) {
        removes.add(ip);
      }
    }
    for (String ip : removes) {
      report.getMachines().remove(ip);
    }
    return report;
  }
Example #9
0
 private void calculateTps(Payload payload, TransactionReport report) {
   try {
     if (payload != null && report != null) {
       boolean isCurrent = payload.getPeriod().isCurrent();
       String ip = payload.getIpAddress();
       Machine machine = report.getMachines().get(ip);
       if (machine == null) {
         return;
       }
       for (TransactionType transType : machine.getTypes().values()) {
         long totalCount = transType.getTotalCount();
         double tps = 0;
         if (isCurrent) {
           double seconds =
               (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
           tps = totalCount / seconds;
         } else {
           double time =
               (report.getEndTime().getTime() - report.getStartTime().getTime()) / (double) 1000;
           tps = totalCount / (double) time;
         }
         transType.setTps(tps);
         for (TransactionName transName : transType.getNames().values()) {
           long totalNameCount = transName.getTotalCount();
           double nameTps = 0;
           if (isCurrent) {
             double seconds =
                 (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
             nameTps = totalNameCount / seconds;
           } else {
             double time =
                 (report.getEndTime().getTime() - report.getStartTime().getTime()) / (double) 1000;
             nameTps = totalNameCount / (double) time;
           }
           transName.setTps(nameTps);
           transName.setTotalPercent((double) totalNameCount / totalCount);
         }
       }
     }
   } catch (Exception e) {
     Cat.logError(e);
   }
 }
Example #10
0
  private void showHourlyReport(Model model, Payload payload) {
    try {
      TransactionReport report = getHourlyReport(payload);

      if (report != null) {
        report.accept(m_computer);
        model.setReport(report);

        String type = payload.getType();
        String sorted = payload.getSortBy();
        String queryName = payload.getQueryName();
        String ip = payload.getIpAddress();
        if (!StringUtils.isEmpty(type)) {
          model.setDisplayNameReport(
              new DisplayNames().display(sorted, type, ip, report, queryName));
        } else {
          model.setDisplayTypeReport(new DisplayTypes().display(sorted, ip, report));
        }
      }
    } catch (Throwable e) {
      Cat.logError(e);
      model.setException(e);
    }
  }
Example #11
0
  private void calculateTps(Payload payload, TransactionReport report) {
    try {
      if (payload != null && report != null) {
        boolean isCurrent = payload.getPeriod().isCurrent();
        double seconds;

        if (isCurrent) {
          seconds = (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
        } else {
          Date endTime = report.getEndTime();
          Date startTime = report.getStartTime();

          if (endTime != null && startTime != null) {
            seconds = (endTime.getTime() - startTime.getTime()) / (double) 1000;
          } else {
            seconds = 60;
          }
        }
        new TpsStatistics(seconds).visitTransactionReport(report);
      }
    } catch (Exception e) {
      Cat.logError(e);
    }
  }