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

modify the channel display and fix channel bug

上级 4caa0277
......@@ -166,16 +166,17 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
Object data = transaction.getData();
if (data != null) {
double value = parseValue(CHANNEL, (String) data);
if (value > 0) {
updateChannel(min, metric, value);
String channel = parseValue(CHANNEL, (String) data);
if (channel != null) {
updateChannel(min, metric, channel, transaction.getDurationInMillis());
}
}
}
}
private void updateChannel(int min, com.dianping.cat.consumer.metric.model.entity.Metric metric, double value) {
com.dianping.cat.consumer.metric.model.entity.Metric detail = metric.findOrCreateMetric(CHANNEL + "=" + (int) (value));
private void updateChannel(int min, com.dianping.cat.consumer.metric.model.entity.Metric metric, String channel,
double value) {
com.dianping.cat.consumer.metric.model.entity.Metric detail = metric.findOrCreateMetric(CHANNEL + "=" + channel);
Point channelPoint = detail.findOrCreatePoint(min);
......@@ -191,27 +192,30 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
if (key != null) {
String data = (String) metric.getData();
double value = parseValue(key, data);
String valueStr = parseValue(key, data);
long current = metric.getTimestamp() / 1000 / 60;
int min = (int) (current % (60));
if (valueStr != null) {
double value = Double.parseDouble(valueStr);
long current = metric.getTimestamp() / 1000 / 60;
int min = (int) (current % (60));
com.dianping.cat.consumer.metric.model.entity.Metric temp = report.findOrCreateMetric(name);
Point point = temp.findOrCreatePoint(min);
com.dianping.cat.consumer.metric.model.entity.Metric temp = report.findOrCreateMetric(name);
Point point = temp.findOrCreatePoint(min);
point.setCount(point.getCount() + 1);
point.setSum(point.getSum() + value);
point.setAvg(point.getSum() / point.getCount());
point.setCount(point.getCount() + 1);
point.setSum(point.getSum() + value);
point.setAvg(point.getSum() / point.getCount());
double channel = parseValue("channel", data);
if (channel > 0) {
updateChannel(min, temp, channel);
String channel = parseValue("channel", data);
if (channel != null) {
updateChannel(min, temp, channel, value);
}
}
}
return 0;
}
public double parseValue(final String key, final String data) {
public String parseValue(final String key, final String data) {
int len = data == null ? 0 : data.length();
int keyLen = key.length();
StringBuilder name = new StringBuilder();
......@@ -224,7 +228,7 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
switch (ch) {
case '&':
if (name.length() == keyLen && name.toString().equals(key)) {
return Double.parseDouble(value.toString());
return value.toString();
}
inName = true;
......@@ -249,10 +253,10 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
}
if (name.length() == keyLen && name.toString().equals(key)) {
return Double.parseDouble(value.toString());
return value.toString();
}
return 0;
return null;
}
private int processTransaction(String group, MetricReport report, MessageTree tree, Transaction t) {
......
......@@ -63,10 +63,11 @@ public class Handler implements PageHandler<Context> {
String channel = payload.getChannel();
if (report != null) {
MetricDisplay display = new MetricDisplay(buildTuanGouMetricConfig(channel),channel, report.getStartTime());
MetricDisplay display = new MetricDisplay(buildTuanGouMetricConfig(channel), channel, report.getStartTime());
display.visitMetricReport(report);
model.setDisplay(display);
model.setChannels(display.getAllChannel());
model.setReport(report);
}
m_jspViewer.view(ctx, model);
......
......@@ -7,6 +7,8 @@ import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.lang.StringUtils;
......@@ -30,6 +32,14 @@ public class MetricDisplay extends BaseVisitor {
private MetricConfig m_config;
private String prefix = "channel=";
private Set<String> m_allChannel = new TreeSet<String>();
public Set<String> getAllChannel() {
return m_allChannel;
}
public MetricDisplay(MetricConfig metricConfig, String channel, Date start) {
m_config = metricConfig;
m_start = start;
......@@ -60,11 +70,19 @@ public class MetricDisplay extends BaseVisitor {
public void visitMetric(Metric metric) {
m_key = metric.getId();
Map<String, Metric> metrics = metric.getMetrics();
if (metrics != null) {
Set<String> keySet = metrics.keySet();
for (String temp : keySet) {
if (temp.startsWith(prefix)) {
m_allChannel.add(temp.substring(prefix.length()));
}
}
}
if (StringUtils.isEmpty(m_channel)) {
buildGraphItem(metric.getPoints().values());
} else {
Map<String, Metric> metrics = metric.getMetrics();
Metric m = metrics.get("channel=" + m_channel);
Metric m = metrics.get(prefix + m_channel);
if (m != null) {
buildGraphItem(m.getPoints().values());
......@@ -113,12 +131,18 @@ public class MetricDisplay extends BaseVisitor {
private String key;
private double[] values = new double[60];
private static final int SIZE = 60;
private double[] values = new double[SIZE];
public GraphItem(Date start, String title, String key) {
this.start = sdf.format(start);
this.title = title;
this.key = key;
for (int i = 0; i < SIZE; i++) {
values[i] = -1;
}
}
public GraphItem addSubTitle(String title) {
......
......@@ -2,6 +2,7 @@ package com.dianping.cat.report.page.metric;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import com.dianping.cat.consumer.metric.model.entity.MetricReport;
import com.dianping.cat.report.page.AbstractReportModel;
......@@ -9,15 +10,17 @@ import com.dianping.cat.report.page.AbstractReportModel;
public class Model extends AbstractReportModel<Action, Context> {
private MetricReport m_report;
private MetricDisplay m_display;
private String m_domain;
private String m_group;
private String m_channel;
private Set<String> m_channels;
public Model(Context ctx) {
super(ctx);
}
......@@ -72,5 +75,13 @@ public class Model extends AbstractReportModel<Action, Context> {
public void setGroup(String group) {
m_group = group;
}
public Set<String> getChannels() {
return m_channels;
}
public void setChannels(Set<String> channels) {
m_channels = channels;
}
}
......@@ -16,6 +16,9 @@ function graph(container, data) {
selection : {
mode : 'x'
},
yaxis : {
min : 0
},
HtmlText : false,
title : data.title
};
......
......@@ -15,7 +15,7 @@
<res:useCss value='${res.css.local.report_css}' target="head-css" />
<res:useCss value='${res.css.local.table_css}' target="head-css" />
<res:useJs value="${res.js.local['bootstrap.min.js']}" target="head-js"/>
<res:useJs value="${res.js.local['flotr2_js']}" target="head-js"/>
<res:useJs value="${res.js.local['flotr2_js']}" target="head-js"/>
<res:useJs value="${res.js.local['metric.js']}" target="head-js"/>
<style type="text/css">
.graph {
......@@ -34,10 +34,13 @@
graph(document.getElementById('${item.title}'), data);
</c:forEach>
var id = "channel"+'${model.channel}';
$('#'+id).addClass("active");
var id = "${model.channel}";
if (id == '') {
$('#allChannel').addClass("active");
} else {
$('#' + id).addClass("active");
}
});
</script>
<div class="report">
<table class="header">
......@@ -57,13 +60,11 @@
<div class="span2">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li id="channel"><a href="?date=${model.date}&group=${model.group}"><strong>团购ALL</strong></a></li>
<li id="allChannel"><a href="?date=${model.date}&group=${model.group}"><strong>团购ALL</strong></a></li>
<li >&nbsp;</li>
<li id="channel1"><a href="?date=${model.date}&group=${model.group}&channel=1">渠道:搜索引擎</a></li>
<li id="channel2"><a href="?date=${model.date}&group=${model.group}&channel=2">渠道:微博推广</a></li>
<li id="channel3"><a href="?date=${model.date}&group=${model.group}&channel=3">渠道:腾讯推广</a></li>
<li id="channel4"><a href="?date=${model.date}&group=${model.group}&channel=4">渠道:内部引流</a></li>
<li id="channel5"><a href="?date=${model.date}&group=${model.group}&channel=5">渠道:团800</a></li>
<c:forEach var="item" items="${model.channels}" varStatus="status">
<li id="${item}"><a href="?date=${model.date}&group=${model.group}&channel=${item}">${item}</a></li>
</c:forEach>
</ul>
</div><!--/.well -->
</div><!--/span-->
......
......@@ -13,20 +13,20 @@ public class TestBusinessMessage {
for (int i = 0; i < 1000; i++) {
Transaction t = Cat.newTransaction("URL", "/index");
Cat.logMetric("order", "quantity", i, "channel", i % 5);
t.addData("channel=" + i % 5);
Cat.logMetric("order", "quantity", i, "channel", "channel"+i % 5);
t.addData("channel=channel" + i % 5);
t.complete();
}
for (int i = 0; i < 900; i++) {
Transaction t = Cat.newTransaction("URL", "/detail");
Cat.logMetric("payment.pending", "amount", i, "channel", i % 5);
t.addData("channel=" + i % 5);
Cat.logMetric("payment.pending", "amount", i, "channel","channel"+ i % 5);
t.addData("channel=channel" + i % 5);
t.complete();
}
for (int i = 0; i < 500; i++) {
Transaction t = Cat.newTransaction("URL", "/order/submitOrder");
Cat.logMetric("payment.success", "amount", i, "channel", i % 5);
t.addData("channel=" + i % 5);
Cat.logMetric("payment.success", "amount", i, "channel", "channel"+i % 5);
t.addData("channel=channel" + i % 5);
t.complete();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册