1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| public class TransactionAnalyzer extends AbstractMessageAnalyzer<TransactionReport> implements LogEnabled { @Inject(ID) private ReportManager<TransactionReport> m_reportManager;
@Override public void process(MessageTree tree) { String domain = tree.getDomain(); TransactionReport report = m_reportManager.getHourlyReport(getStartTime(), domain, true); List<Transaction> transactions = tree.findOrCreateTransactions();
for (Transaction t : transactions) { String data = String.valueOf(t.getData());
if (data.length() > 0 && data.charAt(0) == CatConstants.BATCH_FLAG) { processBatchTransaction(tree, report, t, data); } else { processTransaction(report, tree, t); } }
if (System.currentTimeMillis() > m_nextClearTime) { m_nextClearTime = m_nextClearTime + TimeHelper.ONE_MINUTE;
Threads.forGroup("cat").start(new Runnable() {
@Override public void run() { cleanUpReports(); } }); } }
private void processBatchTransaction(MessageTree tree, TransactionReport report, Transaction t, String data) { String[] tabs = data.substring(1).split(CatConstants.SPLIT); int total = Integer.parseInt(tabs[0]); int fail = Integer.parseInt(tabs[1]); long sum = Long.parseLong(tabs[2]); String type = t.getType(); String name = t.getName();
String ip = tree.getIpAddress(); TransactionType transactionType = findOrCreateType(report.findOrCreateMachine(ip), type); TransactionName transactionName = findOrCreateName(transactionType, name, report.getDomain()); DurationMeta durations = computeBatchDuration(t, tabs, transactionType, transactionName, report.getDomain());
processTypeAndName(tree, t, transactionType, transactionName, total, fail, sum, durations); }
private void processTransaction(TransactionReport report, MessageTree tree, Transaction t) { String type = t.getType(); String name = t.getName();
if (!m_filterConfigManager.discardTransaction(type, name)) { boolean valid = checkForTruncatedMessage(tree, t);
if (valid) { String ip = tree.getIpAddress(); TransactionType transactionType = findOrCreateType(report.findOrCreateMachine(ip), type); TransactionName transactionName = findOrCreateName(transactionType, name, report.getDomain());
processTypeAndName(t, transactionType, transactionName, tree, t.getDurationInMillis()); } } }
private void processTypeAndName(Transaction t, TransactionType type, TransactionName name, MessageTree tree, double duration) { String messageId = tree.getMessageId();
type.incTotalCount(); name.incTotalCount();
type.setSuccessMessageUrl(messageId); name.setSuccessMessageUrl(messageId);
if (!t.isSuccess()) { type.incFailCount(); name.incFailCount();
String statusCode = formatStatus(t.getStatus());
findOrCreateStatusCode(name, statusCode).incCount(); }
int allDuration = computeDuration((int) duration); double sum = duration * duration;
if (type.getMax() <= duration) { type.setLongestMessageUrl(messageId); } if (name.getMax() <= duration) { name.setLongestMessageUrl(messageId); } name.setMax(Math.max(name.getMax(), duration)); name.setMin(Math.min(name.getMin(), duration)); name.setSum(name.getSum() + duration); name.setSum2(name.getSum2() + sum); name.findOrCreateAllDuration(allDuration).incCount();
type.setMax(Math.max(type.getMax(), duration)); type.setMin(Math.min(type.getMin(), duration)); type.setSum(type.getSum() + duration); type.setSum2(type.getSum2() + sum); type.findOrCreateAllDuration(allDuration).incCount();
long current = t.getTimestamp() / 1000 / 60; int min = (int) (current % (60)); boolean statistic = m_statisticManager.shouldStatistic(type.getId(), tree.getDomain());
processNameGraph(t, name, min, duration, statistic, allDuration); processTypeRange(t, type, min, duration, statistic, allDuration); } }
|