示例#1
0
文件: Handler.java 项目: ray-dong/cat
  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;
    }
  }
示例#2
0
 @Override
 public void visitName(TransactionName name) {
   if (name.getId().indexOf("2529898") > -1) {
     System.out.println(name.getId());
   }
   super.visitName(name);
 }
示例#3
0
文件: Handler.java 项目: LyneLiu/cat
  private void transformTo60MinuteData(TransactionName transactionName) {
    Map<Integer, Range> rangeMap = transactionName.getRanges();
    Map<Integer, Range> rangeMapCopy = new LinkedHashMap<Integer, Range>();
    Set<Integer> keys = rangeMap.keySet();
    int minute, completeMinute, count, fails;
    double sum, avg;
    boolean tranform = true;

    if (keys.size() <= 12) {
      for (int key : keys) {
        if (key % 5 != 0) {
          tranform = false;
          break;
        }
      }
    } else {
      tranform = false;
    }

    if (tranform) {
      for (Entry<Integer, Range> entry : rangeMap.entrySet()) {
        Range range = entry.getValue();
        Range r =
            new Range(range.getValue())
                .setCount(range.getCount())
                .setSum(range.getSum())
                .setFails(range.getFails())
                .setAvg(range.getAvg());

        rangeMapCopy.put(entry.getKey(), r);
      }

      for (Entry<Integer, Range> entry : rangeMapCopy.entrySet()) {
        Range range = entry.getValue();
        minute = range.getValue();
        count = range.getCount() / 5;
        fails = range.getFails() / 5;
        sum = range.getSum() / 5;
        avg = range.getAvg();

        for (int i = 0; i < 5; i++) {
          completeMinute = minute + i;

          transactionName
              .findOrCreateRange(completeMinute)
              .setCount(count)
              .setFails(fails)
              .setSum(sum)
              .setAvg(avg);
        }
      }
    }
  }
示例#4
0
文件: Handler.java 项目: LyneLiu/cat
  private void buildTransactionNamePieChart(List<TransactionNameModel> names, Model model) {
    PieChart chart = new PieChart();
    List<Item> items = new ArrayList<Item>();

    for (int i = 1; i < names.size(); i++) {
      TransactionNameModel name = names.get(i);
      Item item = new Item();
      TransactionName transaction = name.getDetail();
      item.setNumber(transaction.getTotalCount()).setTitle(transaction.getId());
      items.add(item);
    }

    chart.addItems(items);
    model.setPieChart(new JsonBuilder().toJson(chart));
  }
示例#5
0
文件: Handler.java 项目: ray-dong/cat
 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);
   }
 }
示例#6
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;
  }
  @Override
  public void visitType(TransactionType type) {
    if ("URL".equals(type.getId())) {
      Map<String, TransactionName> transactionNames = type.getNames();

      Set<String> names = transactionNames.keySet();
      Set<String> invalidates = new HashSet<String>();

      for (String temp : names) {
        int length = temp.length();

        for (int i = 0; i < length; i++) {
          // invalidate char
          if (temp.charAt(i) > 126 || temp.charAt(i) < 33) {
            invalidates.add(temp);
            continue;
          }
        }
      }

      for (String name : invalidates) {
        transactionNames.remove(name);
      }

      int size = transactionNames.size();

      if (size > m_maxItems) {
        List<TransactionName> all = new ArrayList<TransactionName>(transactionNames.values());

        Collections.sort(all, new TransactionNameCompator());
        type.getNames().clear();

        for (int i = 0; i < m_maxItems; i++) {
          type.addName(all.get(i));
        }

        TransactionName other = type.findOrCreateName("OTHERS");
        for (int i = m_maxItems; i < size; i++) {
          mergeName(other, all.get(i));
        }
      }

      List<String> toRemove = new ArrayList<String>();
      TransactionName other = type.findOrCreateName("OTHERS");

      transactionNames = type.getNames();
      names = transactionNames.keySet();
      for (String temp : names) {
        TransactionName tansactionName = transactionNames.get(temp);

        if (tansactionName.getTotalCount() == 1) {
          toRemove.add(temp);
          mergeName(other, tansactionName);
        }
      }

      for (String temp : toRemove) {
        transactionNames.remove(temp);
      }
    }
    super.visitType(type);
  }
  private void mergeName(TransactionName old, TransactionName other) {
    old.setTotalCount(old.getTotalCount() + other.getTotalCount());
    old.setFailCount(old.getFailCount() + other.getFailCount());

    if (other.getMin() < old.getMin()) {
      old.setMin(other.getMin());
    }

    if (other.getMax() > old.getMax()) {
      old.setMax(other.getMax());
    }

    old.setSum(old.getSum() + other.getSum());
    old.setSum2(old.getSum2() + other.getSum2());
    old.setLine95Value(0);
    if (old.getTotalCount() > 0) {
      old.setFailPercent(old.getFailCount() * 100.0 / old.getTotalCount());
      old.setAvg(old.getSum() / old.getTotalCount());
    }

    if (old.getSuccessMessageUrl() == null) {
      old.setSuccessMessageUrl(other.getSuccessMessageUrl());
    }

    if (old.getFailMessageUrl() == null) {
      old.setFailMessageUrl(other.getFailMessageUrl());
    }
  }
 @Override
 public int compare(TransactionName o1, TransactionName o2) {
   return (int) (o2.getTotalCount() - o1.getTotalCount());
 }