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()); } }
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; }
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)); }
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); } }
@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); }
@Override public int compare(TransactionName o1, TransactionName o2) { return (int) (o2.getTotalCount() - o1.getTotalCount()); }