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 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; } }
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; }
@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); } }
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); } }