提交 c014f35b 编写于 作者: Y yong.you

fix tps calculate to tps

上级 f95c6f04
......@@ -15,22 +15,19 @@ import org.unidal.web.mvc.annotation.InboundActionMeta;
import org.unidal.web.mvc.annotation.OutboundActionMeta;
import org.unidal.web.mvc.annotation.PayloadMeta;
import com.dianping.cat.Cat;
import com.dianping.cat.Constants;
import com.dianping.cat.consumer.event.EventAnalyzer;
import com.dianping.cat.consumer.event.EventReportMerger;
import com.dianping.cat.consumer.event.model.entity.EventName;
import com.dianping.cat.consumer.event.model.entity.EventReport;
import com.dianping.cat.consumer.event.model.entity.EventType;
import com.dianping.cat.consumer.transaction.TransactionAnalyzer;
import com.dianping.cat.consumer.transaction.TransactionReportMerger;
import com.dianping.cat.consumer.transaction.model.entity.Machine;
import com.dianping.cat.consumer.transaction.model.entity.TransactionName;
import com.dianping.cat.consumer.transaction.model.entity.TransactionReport;
import com.dianping.cat.consumer.transaction.model.entity.TransactionType;
import com.dianping.cat.helper.TimeUtil;
import com.dianping.cat.report.ReportPage;
import com.dianping.cat.report.page.PayloadNormalizer;
import com.dianping.cat.report.page.event.EventMergeManager;
import com.dianping.cat.report.page.event.TpsStatistics;
import com.dianping.cat.report.page.model.spi.ModelService;
import com.dianping.cat.report.page.transaction.MergeAllMachine;
import com.dianping.cat.report.page.transaction.MergeAllName;
......@@ -76,75 +73,38 @@ public class Handler implements PageHandler<Context> {
private void calculateEventTps(Payload payload, EventReport report) {
if (payload != null && report != null) {
boolean isCurrent = payload.getPeriod().isCurrent();
String ip = payload.getIpAddress();
com.dianping.cat.consumer.event.model.entity.Machine machine = report.getMachines().get(ip);
if (machine == null) {
return;
}
for (EventType eventType : machine.getTypes().values()) {
long totalCount = eventType.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;
}
eventType.setTps(tps);
for (EventName transName : eventType.getNames().values()) {
long totalNameCount = transName.getTotalCount();
double nameTps = 0;
try {
if (payload != null && report != null) {
boolean isCurrent = payload.getPeriod().isCurrent();
double seconds;
if (isCurrent) {
double seconds = (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
nameTps = totalNameCount / seconds;
seconds = (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
} else {
double time = (report.getEndTime().getTime() - report.getStartTime().getTime()) / (double) 1000;
nameTps = totalNameCount / (double) time;
seconds = (report.getEndTime().getTime() - report.getStartTime().getTime()) / (double) 1000;
}
transName.setTps(nameTps);
new TpsStatistics(seconds).visitEventReport(report);
}
} catch (Exception e) {
Cat.logError(e);
}
}
}
private void calculateTransactionTps(Payload payload, TransactionReport report) {
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;
try {
if (payload != null && report != null) {
boolean isCurrent = payload.getPeriod().isCurrent();
double seconds;
if (isCurrent) {
double seconds = (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
nameTps = totalNameCount / seconds;
seconds = (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
} else {
double time = (report.getEndTime().getTime() - report.getStartTime().getTime()) / (double) 1000;
nameTps = totalNameCount / (double) time;
seconds = (report.getEndTime().getTime() - report.getStartTime().getTime()) / (double) 1000;
}
transName.setTps(nameTps);
new com.dianping.cat.report.page.transaction.TpsStatistics(seconds).visitTransactionReport(report);
}
} catch (Exception e) {
Cat.logError(e);
}
}
}
......
......@@ -22,7 +22,6 @@ import com.dianping.cat.consumer.event.EventAnalyzer;
import com.dianping.cat.consumer.event.model.entity.EventName;
import com.dianping.cat.consumer.event.model.entity.EventReport;
import com.dianping.cat.consumer.event.model.entity.EventType;
import com.dianping.cat.consumer.event.model.entity.Machine;
import com.dianping.cat.helper.TimeUtil;
import com.dianping.cat.report.ReportPage;
import com.dianping.cat.report.graph.GraphBuilder;
......@@ -74,41 +73,19 @@ public class Handler implements PageHandler<Context> {
}
private void calculateTps(Payload payload, EventReport report) {
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 (EventType eventType : machine.getTypes().values()) {
long totalCount = eventType.getTotalCount();
double tps = 0;
try {
if (payload != null && report != null) {
boolean isCurrent = payload.getPeriod().isCurrent();
double seconds;
if (isCurrent) {
double seconds = (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
tps = totalCount / seconds;
seconds = (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
} else {
double time = (report.getEndTime().getTime() - report.getStartTime().getTime()) / (double) 1000;
tps = totalCount / (double) time;
}
eventType.setTps(tps);
for (EventName transName : eventType.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(totalNameCount / (double) totalCount);
seconds = (report.getEndTime().getTime() - report.getStartTime().getTime()) / (double) 1000;
}
new TpsStatistics(seconds).visitEventReport(report);
}
} catch (Exception e) {
Cat.logError(e);
}
}
......
package com.dianping.cat.report.page.event;
import com.dianping.cat.consumer.event.model.entity.EventName;
import com.dianping.cat.consumer.event.model.entity.EventType;
import com.dianping.cat.consumer.event.model.transform.BaseVisitor;
public class TpsStatistics extends BaseVisitor {
public double m_duration;
public TpsStatistics(double duration) {
m_duration = duration;
}
@Override
public void visitName(EventName name) {
name.setTps(name.getTotalCount() * 1.0 / m_duration);
}
@Override
public void visitType(EventType type) {
type.setTps(type.getTotalCount() * 1.0 / m_duration);
super.visitType(type);
}
}
......@@ -18,7 +18,6 @@ import org.unidal.web.mvc.annotation.PayloadMeta;
import com.dianping.cat.Cat;
import com.dianping.cat.Constants;
import com.dianping.cat.consumer.transaction.TransactionAnalyzer;
import com.dianping.cat.consumer.transaction.model.entity.Machine;
import com.dianping.cat.consumer.transaction.model.entity.TransactionName;
import com.dianping.cat.consumer.transaction.model.entity.TransactionReport;
import com.dianping.cat.consumer.transaction.model.entity.TransactionType;
......@@ -85,36 +84,13 @@ public class Handler implements PageHandler<Context> {
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);
}
double seconds;
if (isCurrent) {
seconds = (System.currentTimeMillis() - payload.getCurrentDate()) / (double) 1000;
} else {
seconds = (report.getEndTime().getTime() - report.getStartTime().getTime()) / (double) 1000;
}
new TpsStatistics(seconds).visitTransactionReport(report);
}
} catch (Exception e) {
Cat.logError(e);
......
package com.dianping.cat.report.page.transaction;
import com.dianping.cat.consumer.transaction.model.entity.TransactionName;
import com.dianping.cat.consumer.transaction.model.entity.TransactionType;
import com.dianping.cat.consumer.transaction.model.transform.BaseVisitor;
public class TpsStatistics extends BaseVisitor {
public double m_duration;
public TpsStatistics(double duration) {
m_duration = duration;
}
@Override
public void visitName(TransactionName name) {
name.setTps(name.getTotalCount() * 1.0 / m_duration);
}
@Override
public void visitType(TransactionType type) {
type.setTps(type.getTotalCount() * 1.0 / m_duration);
super.visitType(type);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册