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

refator metric problem

上级 ea9c917c
package com.dianping.cat.consumer.advanced;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
public class BussinessConfigManager implements Initializable {
// key is domain
private Map<String, Map<Integer, List<BusinessConfig>>> m_configs = new ConcurrentHashMap<String, Map<Integer, List<BusinessConfig>>>();
// key is group
private Map<String, List<BusinessConfig>> m_groupConfigs = new ConcurrentHashMap<String, List<BusinessConfig>>();
private Map<String, String> m_domainGroup = new ConcurrentHashMap<String, String>();
private Set<String> m_groups = new TreeSet<String>();
public Set<String> getGroups() {
return m_groups;
}
public List<BusinessConfig> getUrlConfigs(String domain) {
return getMetricConfigsByType(domain, BusinessConfig.URL);
}
public List<BusinessConfig> getMetricConfigs(String domain) {
return getMetricConfigsByType(domain, BusinessConfig.METRIC);
}
public List<BusinessConfig> getConfigs(String group) {
List<BusinessConfig> list = m_groupConfigs.get(group);
if (list != null) {
Collections.sort(list, new BusinessConfigCompator());
return list;
} else {
return new ArrayList<BusinessConfig>();
}
}
private List<BusinessConfig> getMetricConfigsByType(String domain, int type) {
Map<Integer, List<BusinessConfig>> configMap = m_configs.get(domain);
if (configMap != null) {
List<BusinessConfig> config = configMap.get(type);
if (config != null) {
return config;
}
}
return new ArrayList<BusinessConfig>();
}
private BussinessConfigManager addConfig(BusinessConfig config) {
String domain = config.getDomain();
Map<Integer, List<BusinessConfig>> configsMap = m_configs.get(domain);
if (configsMap == null) {
configsMap = new ConcurrentHashMap<Integer, List<BusinessConfig>>();
m_configs.put(config.getDomain(), configsMap);
}
int type = config.getType();
List<BusinessConfig> configs = configsMap.get(type);
if (configs == null) {
configs = new ArrayList<BusinessConfig>();
configsMap.put(config.getType(), configs);
}
configs.add(config);
String group = config.getGroup();
List<BusinessConfig> groupConfigs = m_groupConfigs.get(group);
if (groupConfigs == null) {
groupConfigs = new ArrayList<BusinessConfig>();
m_groupConfigs.put(group, groupConfigs);
}
groupConfigs.add(config);
m_domainGroup.put(domain, group);
return this;
}
@Override
public void initialize() throws InitializationException {
String TuanGou = "TuanGou";
String TuanGouWeb = "TuanGouWeb";
String PayOrder = "PayOrder";
String Cat = "Cat";
// tuangou.put("order", "quantity");
// tuangou.put("payment.pending", "amount");
// tuangou.put("payment.success", "amount");
m_groups.add(Cat);
m_groups.add(TuanGou);
BusinessConfig config = new BusinessConfig();
config.setGroup(Cat).setDomain(Cat).setType(BusinessConfig.URL);
config.setViewOrder(1).setMainKey("t").setClassifications(null);
config.setTitle("Transaction").setShowCount(true).setShowAvg(true).setShowSum(true);
addConfig(config);
config = new BusinessConfig();
config.setGroup(Cat).setDomain(Cat).setType(BusinessConfig.URL);
config.setViewOrder(2).setMainKey("e").setClassifications(null);
config.setTitle("Event").setShowCount(true).setShowAvg(false).setShowSum(false);
addConfig(config);
config = new BusinessConfig();
config.setGroup(Cat).setDomain(Cat).setType(BusinessConfig.URL);
config.setViewOrder(3).setMainKey("home").setClassifications(null);
config.setTitle("Home").setShowCount(true).setShowAvg(false).setShowSum(false);
addConfig(config);
config = new BusinessConfig();
config.setGroup(TuanGou).setDomain(TuanGouWeb).setType(BusinessConfig.URL);
config.setViewOrder(1).setMainKey("/index").setClassifications("channel");
config.setTitle(MetricTitle.INDEX).setShowCount(true).setShowAvg(false).setShowSum(false);
addConfig(config);
config = new BusinessConfig();
config.setGroup(TuanGou).setDomain(TuanGouWeb).setType(BusinessConfig.URL);
config.setViewOrder(2).setMainKey("/detail").setClassifications("channel");
config.setTitle(MetricTitle.DETAIL).setShowCount(true).setShowAvg(false).setShowSum(false);
addConfig(config);
config = new BusinessConfig();
config.setGroup(TuanGou).setDomain(PayOrder).setType(BusinessConfig.URL);
config.setViewOrder(3).setMainKey("/order/submitOrder").setClassifications("channel");
config.setTitle(MetricTitle.PAY).setShowCount(true).setShowAvg(false).setShowSum(false);
addConfig(config);
config = new BusinessConfig();
config.setGroup(TuanGou).setDomain(PayOrder).setType(BusinessConfig.METRIC);
config.setViewOrder(4).setMainKey("order").setClassifications("channel").setTarget("quantity");
config.setTitle(MetricTitle.ORDER).setShowCount(true).setShowAvg(false).setShowSum(false);
addConfig(config);
config = new BusinessConfig();
config.setGroup(TuanGou).setDomain(PayOrder).setType(BusinessConfig.METRIC);
config.setViewOrder(5).setMainKey("payment.pending").setClassifications("channel").setTarget("amount");
config.setTitle(MetricTitle.SUCCESS).setShowCount(false).setShowAvg(false).setShowSum(false);
addConfig(config);
config = new BusinessConfig();
config.setGroup(TuanGou).setDomain(PayOrder).setType(BusinessConfig.METRIC);
config.setViewOrder(6).setMainKey("payment.success").setClassifications("channel").setTarget("amount");
config.setTitle(MetricTitle.SUCCESS).setShowCount(true).setShowAvg(false).setShowSum(true);
addConfig(config);
}
public static class BusinessConfigCompator implements Comparator<BusinessConfig> {
@Override
public int compare(BusinessConfig o1, BusinessConfig o2) {
return o1.getViewOrder() - o2.getViewOrder();
}
}
public static class BusinessConfig {
public static final int URL = 1;
public static final int METRIC = 2;
public static final String Suffix_SUM = "(总和)";
public static final String Suffix_COUNT = "(次数)";
public static final String Suffix_AVG = "(平均)";
private String m_group;
private String m_domain;
private int m_type;
private int m_viewOrder;
private String m_mainKey;
private String m_target;
private String m_classifications;
private String m_title;
private boolean m_showSum;
private boolean m_showCount;
private boolean m_showAvg;
public String getTarget() {
return m_target;
}
public BusinessConfig setTarget(String target) {
m_target = target;
return this;
}
public String getClassifications() {
return m_classifications;
}
public String getDomain() {
return m_domain;
}
public String getGroup() {
return m_group;
}
public String getMainKey() {
return m_mainKey;
}
public String getTitle() {
return m_title;
}
public int getType() {
return m_type;
}
public int getViewOrder() {
return m_viewOrder;
}
public boolean isShowAvg() {
return m_showAvg;
}
public boolean isShowCount() {
return m_showCount;
}
public boolean isShowSum() {
return m_showSum;
}
public BusinessConfig setClassifications(String childKeys) {
m_classifications = childKeys;
return this;
}
public BusinessConfig setDomain(String domain) {
m_domain = domain;
return this;
}
public BusinessConfig setGroup(String group) {
m_group = group;
return this;
}
public BusinessConfig setMainKey(String mainKey) {
m_mainKey = mainKey;
return this;
}
public BusinessConfig setShowAvg(boolean showAvg) {
m_showAvg = showAvg;
return this;
}
public BusinessConfig setShowCount(boolean showCount) {
m_showCount = showCount;
return this;
}
public BusinessConfig setShowSum(boolean showSum) {
m_showSum = showSum;
return this;
}
public BusinessConfig setTitle(String title) {
m_title = title;
return this;
}
public BusinessConfig setType(int type) {
m_type = type;
return this;
}
public BusinessConfig setViewOrder(int viewOrder) {
m_viewOrder = viewOrder;
return this;
}
}
public class MetricTitle {
public static final String INDEX = "团购首页";
public static final String DETAIL = "团购详情";
public static final String PAY = "支付页面";
public static final String ORDER = "订单创建";
public static final String SUCCESS = "支付金额(单位:元)";
}
public String getGroup(String domain) {
return m_domainGroup.get(domain);
}
}
......@@ -2,7 +2,6 @@ package com.dianping.cat.consumer.advanced;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -17,6 +16,7 @@ import com.dianping.cat.Cat;
import com.dianping.cat.CatConstants;
import com.dianping.cat.configuration.NetworkInterfaceManager;
import com.dianping.cat.consumer.AbstractMessageAnalyzer;
import com.dianping.cat.consumer.advanced.BussinessConfigManager.BusinessConfig;
import com.dianping.cat.consumer.metric.model.entity.MetricReport;
import com.dianping.cat.consumer.metric.model.entity.Point;
import com.dianping.cat.consumer.metric.model.transform.DefaultNativeBuilder;
......@@ -38,35 +38,12 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
@Inject
private BusinessReportDao m_businessReportDao;
@Inject
private BussinessConfigManager m_configManager;
// key is project line,such as tuangou
private Map<String, MetricReport> m_reports = new HashMap<String, MetricReport>();
private static final String TUANGOU = "TuanGou";
private static final String CHANNEL = "channel";
private static Map<String, Set<String>> s_urls = new HashMap<String, Set<String>>();
private static Map<String, Map<String, String>> s_metric = new HashMap<String, Map<String, String>>();
static {
Set<String> urls = new HashSet<String>();
urls.add("/index");
urls.add("/detail");
urls.add("/order/submitOrder");
s_urls.put(TUANGOU, urls);
}
static {
Map<String, String> tuangou = new HashMap<String, String>();
tuangou.put("order", "quantity");
tuangou.put("payment.pending", "amount");
tuangou.put("payment.success", "amount");
s_metric.put(TUANGOU, tuangou);
}
@Override
public void doCheckpoint(boolean atEnd) {
storeReports(atEnd);
......@@ -82,10 +59,6 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
return m_reports.keySet();
}
public String getGroup(String domain) {
return "TuanGou";
}
public MetricReport getReport(String group) {
MetricReport report = m_reports.get(group);
......@@ -124,8 +97,7 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
@Override
public void process(MessageTree tree) {
String domain = tree.getDomain();
String group = getGroup(domain);
String group = m_configManager.getGroup(domain);
MetricReport report = m_reports.get(group);
if (report == null) {
......@@ -139,7 +111,7 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
Message message = tree.getMessage();
if (message instanceof Transaction) {
processUrl(group, report, (Transaction) message);
processUrl(group, report, (Transaction) message, tree);
}
if (message instanceof Transaction) {
processTransaction(group, report, tree, (Transaction) message);
......@@ -148,35 +120,50 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
}
}
private void processUrl(String group, MetricReport report, Transaction transaction) {
Set<String> urls = s_urls.get(group);
private void processUrl(String group, MetricReport report, Transaction transaction, MessageTree tree) {
String type = transaction.getType();
String name = transaction.getName();
if (type.equals(CatConstants.TYPE_URL) && urls.contains(name)) {
long current = transaction.getTimestamp() / 1000 / 60;
int min = (int) (current % (60));
if (CatConstants.TYPE_URL.equals(type)) {
String name = transaction.getName();
String domain = tree.getDomain();
List<BusinessConfig> configs = m_configManager.getUrlConfigs(domain);
BusinessConfig config = null;
com.dianping.cat.consumer.metric.model.entity.Metric metric = report.findOrCreateMetric(name);
Point point = metric.findOrCreatePoint(min);
for (BusinessConfig c : configs) {
if (c.getMainKey().equals(name)) {
config = c;
break;
}
}
if (config != null) {
long current = transaction.getTimestamp() / 1000 / 60;
int min = (int) (current % (60));
point.setCount(point.getCount() + 1);
point.setSum(point.getSum() + transaction.getDurationInMillis());
point.setAvg(point.getSum() / point.getCount());
com.dianping.cat.consumer.metric.model.entity.Metric metric = report.findOrCreateMetric(name);
Point point = metric.findOrCreatePoint(min);
point.setCount(point.getCount() + 1);
point.setSum(point.getSum() + transaction.getDurationInMillis());
point.setAvg(point.getSum() / point.getCount());
Object data = transaction.getData();
if (data != null) {
String channel = parseValue(CHANNEL, (String) data);
if (channel != null) {
updateChannel(min, metric, channel, transaction.getDurationInMillis());
String childKey = config.getClassifications();
if (childKey != null && childKey.length() > 0) {
Object data = transaction.getData();
if (data != null) {
String channel = parseValue(childKey, (String) data);
if (channel != null) {
updateMetricChild(min, metric, childKey, channel, transaction.getDurationInMillis());
}
}
}
}
}
}
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);
private void updateMetricChild(int min, com.dianping.cat.consumer.metric.model.entity.Metric metric,
String childKey, String childValue, double value) {
com.dianping.cat.consumer.metric.model.entity.Metric detail = metric.findOrCreateMetric(childKey + "="
+ childValue);
Point channelPoint = detail.findOrCreatePoint(min);
......@@ -187,12 +174,20 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
private int processMetric(String group, MetricReport report, MessageTree tree, Metric metric) {
String name = metric.getName();
Map<String, String> metrics = s_metric.get(group);
String key = metrics.get(name);
String domain = tree.getDomain();
List<BusinessConfig> configs = m_configManager.getMetricConfigs(domain);
if (key != null) {
BusinessConfig config = null;
for (BusinessConfig c : configs) {
if (c.getMainKey().equals(name)) {
config = c;
break;
}
}
if (config != null) {
String data = (String) metric.getData();
String valueStr = parseValue(key, data);
String valueStr = parseValue(config.getTarget(), data);
if (valueStr != null) {
double value = Double.parseDouble(valueStr);
......@@ -206,9 +201,14 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
point.setSum(point.getSum() + value);
point.setAvg(point.getSum() / point.getCount());
String channel = parseValue("channel", data);
if (channel != null) {
updateChannel(min, temp, channel, value);
String childKey = config.getClassifications();
if (childKey != null && childKey.length() > 0) {
if (data != null) {
String childValue = parseValue(childKey, data);
if (childValue != null) {
updateMetricChild(min, temp, childKey, childValue, value);
}
}
}
}
}
......@@ -315,7 +315,6 @@ public class MetricAnalyzer extends AbstractMessageAnalyzer<MetricReport> implem
r.setPeriod(period);
r.setIp(ip);
r.setType(binary);
// r.setBinaryContent(DefaultNativeBuilder.build(report));
r.setContent(DefaultNativeBuilder.build(report));
r.setCreationDate(new Date());
......
......@@ -16,6 +16,7 @@ import com.dianping.cat.configuration.ServerConfigManager;
import com.dianping.cat.consumer.CatConsumerAdvancedModule;
import com.dianping.cat.consumer.DomainManager;
import com.dianping.cat.consumer.MessageAnalyzer;
import com.dianping.cat.consumer.advanced.BussinessConfigManager;
import com.dianping.cat.consumer.advanced.CrossAnalyzer;
import com.dianping.cat.consumer.advanced.DatabaseAnalyzer;
import com.dianping.cat.consumer.advanced.DatabaseParser;
......@@ -31,29 +32,31 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
public List<Component> defineComponents() {
List<Component> all = new ArrayList<Component>();
all.add(C(BussinessConfigManager.class));
all.add(C(DomainManager.class, DomainManager.class).req(ServerConfigManager.class, HostinfoDao.class));
all.add(C(SqlParseManager.class).req(SqltableDao.class));
all.add(C(DatabaseParser.class));
all.add(C(MessageAnalyzer.class, CrossAnalyzer.ID, CrossAnalyzer.class).is(PER_LOOKUP) //
.req(BucketManager.class, ReportDao.class));
all.add(C(MessageAnalyzer.class, DatabaseAnalyzer.ID, DatabaseAnalyzer.class).is(PER_LOOKUP) //
.req(BucketManager.class, ReportDao.class, SqlParseManager.class,DatabaseParser.class));
.req(BucketManager.class, ReportDao.class, SqlParseManager.class, DatabaseParser.class));
all.add(C(MessageAnalyzer.class, SqlAnalyzer.ID, SqlAnalyzer.class).is(PER_LOOKUP) //
.req(BucketManager.class, ReportDao.class, SqlParseManager.class,DatabaseParser.class));
.req(BucketManager.class, ReportDao.class, SqlParseManager.class, DatabaseParser.class));
all.add(C(MessageAnalyzer.class, MatrixAnalyzer.ID, MatrixAnalyzer.class).is(PER_LOOKUP) //
.req(BucketManager.class, ReportDao.class));
all.add(C(MessageAnalyzer.class, DependencyAnalyzer.ID, DependencyAnalyzer.class).is(PER_LOOKUP) //
.req(BucketManager.class, ReportDao.class, DomainManager.class,DatabaseParser.class));
.req(BucketManager.class, ReportDao.class, DomainManager.class, DatabaseParser.class));
all.add(C(MessageAnalyzer.class, MetricAnalyzer.ID, MetricAnalyzer.class).is(PER_LOOKUP) //
.req(BucketManager.class, BusinessReportDao.class));
.req(BucketManager.class, BusinessReportDao.class, BussinessConfigManager.class));
all.add(C(Module.class, CatConsumerAdvancedModule.ID, CatConsumerAdvancedModule.class));
......
<plexus>
<components>
<component>
<role>com.dianping.cat.consumer.advanced.BussinessConfigManager</role>
<implementation>com.dianping.cat.consumer.advanced.BussinessConfigManager</implementation>
</component>
<component>
<role>com.dianping.cat.consumer.DomainManager</role>
<implementation>com.dianping.cat.consumer.DomainManager</implementation>
......@@ -125,6 +129,9 @@
<requirement>
<role>com.dainping.cat.consumer.advanced.dal.BusinessReportDao</role>
</requirement>
<requirement>
<role>com.dianping.cat.consumer.advanced.BussinessConfigManager</role>
</requirement>
</requirements>
</component>
<component>
......
......@@ -11,10 +11,10 @@ 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.consumer.advanced.BussinessConfigManager;
import com.dianping.cat.consumer.metric.model.entity.MetricReport;
import com.dianping.cat.report.ReportPage;
import com.dianping.cat.report.page.PayloadNormalizer;
import com.dianping.cat.report.page.metric.MetricConfig.MetricFlag;
import com.dianping.cat.report.page.model.spi.ModelRequest;
import com.dianping.cat.report.page.model.spi.ModelResponse;
import com.dianping.cat.report.page.model.spi.ModelService;
......@@ -29,25 +29,10 @@ public class Handler implements PageHandler<Context> {
@Inject
private PayloadNormalizer m_normalizePayload;
private static final String TUAN = "TuanGou";
@Inject
private BussinessConfigManager m_configManager;
private MetricConfig buildTuanGouMetricConfig(String channel) {
MetricConfig config = new MetricConfig();
MetricFlag indexUrl = new MetricFlag("/index", channel, 1, true, false, false, MetricTitle.INDEX);
MetricFlag detailUrl = new MetricFlag("/detail", channel, 2, true, false, false, MetricTitle.DETAIL);
MetricFlag payUrl = new MetricFlag("/order/submitOrder", channel, 3, true, false, false, MetricTitle.PAY);
MetricFlag orderKey = new MetricFlag("order", channel, 4, false, true, false, MetricTitle.ORDER);
MetricFlag totalKey = new MetricFlag("payment.success", channel, 5, false, true, false, MetricTitle.SUCCESS);
// MetricFlag sumKey = new MetricFlag("payment.pending", 5, false, true, false);
config.put(indexUrl);
config.put(detailUrl);
config.put(payUrl);
config.put(orderKey);
config.put(totalKey);
return config;
}
private static final String TUAN = "TuanGou";
private MetricReport getReport(Payload payload) {
String group = payload.getGroup();
......@@ -80,6 +65,7 @@ public class Handler implements PageHandler<Context> {
public void handleOutbound(Context ctx) throws ServletException, IOException {
Model model = new Model(ctx);
Payload payload = ctx.getPayload();
normalize(model, payload);
MetricReport report = getReport(payload);
......@@ -90,36 +76,29 @@ public class Handler implements PageHandler<Context> {
if (startTime == null) {
startTime = payload.getHistoryStartDate();
}
MetricDisplay display = new MetricDisplay(buildTuanGouMetricConfig(channel), channel, startTime);
MetricDisplay display = new MetricDisplay(m_configManager.getConfigs(payload.getGroup()), channel, startTime);
display.visitMetricReport(report);
model.setDisplay(display);
model.setChannels(display.getAllChannel());
model.setChannels(display.getAllChildKeyValues());//TODO
model.setReport(report);
model.setGroups(m_configManager.getGroups());
model.setChildKey(display.getChildKey());
model.setChildKeyValues(display.getAllChildKeyValues());
}
m_jspViewer.view(ctx, model);
}
private void normalize(Model model, Payload payload) {
payload.setGroup(TUAN);
model.setGroup(payload.getGroup());
model.setChannel(payload.getChannel());
model.setPage(ReportPage.METRIC);
m_normalizePayload.normalize(model, payload);
}
public class MetricTitle {
public static final String INDEX = "团购首页(次)";
public static final String DETAIL = "团购详情(次)";
public static final String PAY = "支付页面(次)";
public static final String ORDER = "订单创建数量(个)";
public static final String SUCCESS = "支付金额(元)";
String group = payload.getGroup();
if (group == null || group.length() == 0) {
payload.setGroup(TUAN);
}
model.setGroup(payload.getGroup());
}
}
package com.dianping.cat.report.page.metric;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
public class MetricConfig {
private Map<String, MetricFlag> m_flags = new LinkedHashMap<String, MetricFlag>();
public MetricFlag get(String key) {
return m_flags.get(key);
}
public Collection<MetricFlag> getFlags() {
return m_flags.values();
}
public void put(MetricFlag flag) {
m_flags.put(flag.getKey(), flag);
}
public static class MetricFlag {
private String m_key;
private String m_key2;
private int m_index;
private boolean m_showCount;
private boolean m_showSum;
private boolean m_showAvg;
private String m_title;
public MetricFlag(String key, String key2, int index, boolean showCount, boolean showSum, boolean showAvg,
String title) {
m_key = key;
m_key2 = key;
m_index = index;
m_showCount = showCount;
m_showSum = showSum;
m_showAvg = showAvg;
m_title = title;
}
public int getIndex() {
return m_index;
}
public String getKey() {
return m_key;
}
public String getKey2() {
return m_key2;
}
public String getTitle() {
return m_title;
}
public boolean isShowAvg() {
return m_showAvg;
}
public boolean isShowCount() {
return m_showCount;
}
public boolean isShowSum() {
return m_showSum;
}
public void setKey2(String key2) {
m_key2 = key2;
}
public void setTitle(String title) {
m_title = title;
}
}
}
......@@ -12,12 +12,12 @@ import java.util.TreeSet;
import org.apache.commons.lang.StringUtils;
import com.dianping.cat.consumer.advanced.BussinessConfigManager.BusinessConfig;
import com.dianping.cat.consumer.metric.model.entity.Metric;
import com.dianping.cat.consumer.metric.model.entity.MetricReport;
import com.dianping.cat.consumer.metric.model.entity.Point;
import com.dianping.cat.consumer.metric.model.transform.BaseVisitor;
import com.dianping.cat.helper.TimeUtil;
import com.dianping.cat.report.page.metric.MetricConfig.MetricFlag;
import com.google.gson.Gson;
public class MetricDisplay extends BaseVisitor {
......@@ -26,34 +26,36 @@ public class MetricDisplay extends BaseVisitor {
private String m_key;
private String m_channel;
private String m_classificationValue;
private Date m_start;
private MetricConfig m_config;
private String m_classificationKey;
private String prefix = "channel=";
private Set<String> m_allChildKeyValues = new TreeSet<String>();
private Set<String> m_allChannel = new TreeSet<String>();
public MetricDisplay(MetricConfig metricConfig, String channel, Date start) {
m_config = metricConfig;
public MetricDisplay(List<BusinessConfig> configs, String classificationValue, Date start) {
m_start = start;
m_channel = channel;
m_classificationValue = classificationValue;
for (MetricFlag flag : m_config.getFlags()) {
for (BusinessConfig flag : configs) {
String title = flag.getTitle();
String classifications = flag.getClassifications();
if (classifications != null && classifications.length() > 0) {
m_classificationKey = classifications;
}
if (flag.isShowSum()) {
String key = flag.getKey() + ":sum";
m_metrics.put(key, new GraphItem(m_start, title, flag.getKey()));
String key = flag.getMainKey() + ":sum";
m_metrics.put(key, new GraphItem(m_start, title + BusinessConfig.Suffix_SUM, flag.getMainKey()));
}
if (flag.isShowCount()) {
String key = flag.getKey() + ":count";
m_metrics.put(key, new GraphItem(m_start, title, flag.getKey()));
String key = flag.getMainKey() + ":count";
m_metrics.put(key, new GraphItem(m_start, title + BusinessConfig.Suffix_COUNT, flag.getMainKey()));
}
if (flag.isShowAvg()) {
String key = flag.getKey() + ":avg";
m_metrics.put(key, new GraphItem(m_start, title, flag.getKey()));
String key = flag.getMainKey() + ":avg";
m_metrics.put(key, new GraphItem(m_start, title + BusinessConfig.Suffix_AVG, flag.getMainKey()));
}
}
}
......@@ -81,8 +83,12 @@ public class MetricDisplay extends BaseVisitor {
}
}
public Set<String> getAllChannel() {
return m_allChannel;
public Set<String> getAllChildKeyValues() {
return m_allChildKeyValues;
}
public String getChildKey() {
return m_classificationKey;
}
public List<GraphItem> getGroups() {
......@@ -97,15 +103,13 @@ public class MetricDisplay extends BaseVisitor {
if (metrics != null) {
Set<String> keySet = metrics.keySet();
for (String temp : keySet) {
if (temp.startsWith(prefix)) {
m_allChannel.add(temp.substring(prefix.length()));
}
m_allChildKeyValues.add(temp.substring(temp.indexOf('=') + 1));
}
}
if (StringUtils.isEmpty(m_channel)) {
if (StringUtils.isEmpty(m_classificationValue)) {
buildGraphItem(metric.getPoints().values());
} else {
Metric m = metrics.get(prefix + m_channel);
Metric m = metrics.get(m_classificationKey + '=' + m_classificationValue);
if (m != null) {
buildGraphItem(m.getPoints().values());
......
......@@ -19,6 +19,12 @@ public class Model extends AbstractReportModel<Action, Context> {
private Set<String> m_channels;
private Set<String> m_groups;
private Set<String> m_childKeyValues;
private String m_childKey;
public Model(Context ctx) {
super(ctx);
}
......@@ -78,4 +84,28 @@ public class Model extends AbstractReportModel<Action, Context> {
m_report = report;
}
public void setGroups(Set<String> groups) {
m_groups =groups;
}
public Set<String> getGroups() {
return m_groups;
}
public void setChildKeyValues(Set<String> childKeys) {
m_childKeyValues = childKeys;
}
public Set<String> getChildKeyValues() {
return m_childKeyValues;
}
public String getChildKey() {
return m_childKey;
}
public void setChildKey(String childKey) {
m_childKey = childKey;
}
}
......@@ -12,7 +12,7 @@ public class Payload extends AbstractReportPayload<Action> {
@FieldMeta("op")
private Action m_action;
@FieldMeta("op")
@FieldMeta("group")
private String m_group;
@FieldMeta("channel")
......
......@@ -88,19 +88,24 @@ public class ReportFacade implements LogEnabled, Initializable {
m_logger.info("no report builder for type:" + " " + reportName);
return false;
} else {
boolean result = false;
if (type == TYPE_DAILY) {
return reportBuilder.buildDailyReport(reportName, reportDomain, reportPeriod);
result = reportBuilder.buildDailyReport(reportName, reportDomain, reportPeriod);
} else if (type == TYPE_HOUR) {
return reportBuilder.buildHourReport(reportName, reportDomain, reportPeriod);
result = reportBuilder.buildHourReport(reportName, reportDomain, reportPeriod);
} else if (type == TYPE_WEEK) {
return reportBuilder.buildWeeklyReport(reportName, reportDomain, reportPeriod);
result = reportBuilder.buildWeeklyReport(reportName, reportDomain, reportPeriod);
} else if (type == TYPE_MONTH) {
return reportBuilder.buildMonthReport(reportName, reportDomain, reportPeriod);
result = reportBuilder.buildMonthReport(reportName, reportDomain, reportPeriod);
}
if (result) {
return result;
} else {
m_logger.error(task.toString());
}
}
} catch (Exception e) {
System.err.println("Flowing is error stack trace:");
e.printStackTrace();
m_logger.error("Error when building report," + e.getMessage(), e);
Cat.logError(e);
return false;
......
......@@ -41,13 +41,13 @@ public class NavigationBar {
ReportPage.SQL,
ReportPage.DATABASE,
ReportPage.MATRIX,
// ReportPage.DATABASE,
//
// ReportPage.MATRIX,
ReportPage.DEPENDENCY,
ReportPage.HEALTH,
// ReportPage.HEALTH,
ReportPage.TOP,
......
......@@ -2445,6 +2445,9 @@
<requirement>
<role>com.dianping.cat.report.page.PayloadNormalizer</role>
</requirement>
<requirement>
<role>com.dianping.cat.consumer.advanced.BussinessConfigManager</role>
</requirement>
</requirements>
</component>
<component>
......@@ -2456,6 +2459,10 @@
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.consumer.advanced.BussinessConfigManager</role>
<implementation>com.dianping.cat.consumer.advanced.BussinessConfigManager</implementation>
</component>
<component>
<role>com.dianping.cat.report.page.jsError.Handler</role>
<implementation>com.dianping.cat.report.page.jsError.Handler</implementation>
......
......@@ -15,16 +15,7 @@
<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['metric.js']}" target="head-js"/>
<style type="text/css">
.graph {
width: 380px;
height: 200px;
margin: 4px auto;
}
.row-fluid .span2{
width:12%;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
<c:forEach var="item" items="${model.display.groups}" varStatus="status">
......@@ -32,12 +23,16 @@
graph(document.getElementById('${item.title}'), data);
</c:forEach>
var id = "${model.channel}";
/* var id = "${model.channel}";
if (id == '') {
$('#allChannel').addClass("active");
} else {
$('#' + id).addClass("active");
}
} */
var group = '${model.group}';
$('#' + group).addClass("active");
var childKey = '${model.channel}';
$('#' + childKey).addClass("active");
});
</script>
<div class="report">
......@@ -58,11 +53,16 @@
<div class="span2">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li id="allChannel"><a href="?date=${model.date}&group=${model.group}"><strong>团购ALL</strong></a></li>
<c:forEach var="item" items="${model.groups}" varStatus="status">
<li class='nav-header' id="${item}"><a href="?date=${model.date}&group=${item}"><strong>${item}</strong></a></li>
<c:if test="${model.group eq item }">
<c:forEach var="item" items="${model.childKeyValues}" varStatus="status">
<li id="${item}"><a href="?date=${model.date}&group=${model.group}&${model.childKey}=${item}">${item}</a></li>
</c:forEach>
</c:if>
</c:forEach>
<li >&nbsp;</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-->
......@@ -77,4 +77,27 @@
</tr>
</table>
</div>
</a:body>
\ No newline at end of file
</a:body>
<style type="text/css">
.graph {
width: 380px;
height: 200px;
margin: 4px auto;
}
.row-fluid .span2{
width:12%;
}
.well {
padding: 10px 10px 10px 19p;
}
.nav-list li a{
padding:2px 15px;
}
.nav li +.nav-header{
margin-top:2px;
}
.nav-header{
padding:5px 3px;
}
</style>
......@@ -5,34 +5,96 @@ import org.junit.Test;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Event;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.spi.internal.DefaultMessageTree;
public class TestBusinessMessage {
private static final String TuanGou = "TuanGouWeb";
private static final String PayOrder = "PayOrder";
@Test
public void test() throws Exception {
while (true) {
for (int i = 0; i < 1000; i++) {
Transaction t = Cat.newTransaction("URL", "/index");
Cat.logMetric("order", "quantity", i, "channel", "channel"+i % 5);
Cat.logEvent("RemoteLink", "sina", Event.SUCCESS, "http://sina.com.cn/");
t.addData("channel=channel" + i % 5);
DefaultMessageTree tree = (DefaultMessageTree) Cat.getManager().getThreadLocalMessageTree();
tree.setDomain(TuanGou);
t.complete();
}
for (int i = 0; i < 900; i++) {
Transaction t = Cat.newTransaction("URL", "/detail");
Cat.logMetric("payment.pending", "amount", i, "channel","channel"+ i % 5);
DefaultMessageTree tree = (DefaultMessageTree) Cat.getManager().getThreadLocalMessageTree();
tree.setDomain(TuanGou);
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", "channel"+i % 5);
DefaultMessageTree tree = (DefaultMessageTree) Cat.getManager().getThreadLocalMessageTree();
tree.setDomain(PayOrder);
Cat.logMetric("order", "quantity", 1, "channel", "channel" + i % 5);
Cat.logMetric("payment.pending", "amount", i, "channel", "channel" + i % 5);
Cat.logMetric("payment.success", "amount", i, "channel", "channel" + i % 5);
t.addData("channel=channel" + i % 5);
t.complete();
}
Thread.sleep(10000);
for (int i = 0; i < 1000; i++) {
Transaction t = Cat.newTransaction("URL", "t");
Cat.logEvent("RemoteLink", "sina", Event.SUCCESS, "http://sina.com.cn/");
t.complete();
}
for (int i = 0; i < 900; i++) {
Transaction t = Cat.newTransaction("URL", "e");
t.complete();
}
for (int i = 0; i < 500; i++) {
Transaction t = Cat.newTransaction("URL", "home");
Cat.logMetric("order", "quantity", 1, "channel", "channel" + i % 5);
Cat.logMetric("payment.pending", "amount", i, "channel", "channel" + i % 5);
Cat.logMetric("payment.success", "amount", i, "channel", "channel" + i % 5);
t.complete();
}
Thread.sleep(1000);
}
}
@Test
public void test2() throws Exception {
while (true) {
for (int i = 0; i < 1000; i++) {
Transaction t = Cat.newTransaction("URL", "/index");
Cat.logEvent("RemoteLink", "sina", Event.SUCCESS, "http://sina.com.cn/");
t.addData("channel=channel" + i % 5);
t.complete();
}
for (int i = 0; i < 900; i++) {
Transaction t = Cat.newTransaction("URL", "/detail");
t.addData("channel=channel" + i % 5);
t.complete();
}
for (int i = 0; i < 500; i++) {
Transaction t = Cat.newTransaction("URL", "/order/submitOrder");
Cat.logMetric("order", "quantity", 1, "channel", "channel" + i % 5);
Cat.logMetric("payment.pending", "amount", i, "channel", "channel" + i % 5);
Cat.logMetric("payment.success", "amount", i, "channel", "channel" + i % 5);
t.addData("channel=channel" + i % 5);
t.complete();
}
Thread.sleep(1000);
break;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册