diff --git a/cat-broker/src/test/java/com/dianping/cat/broker/SingleTest.java b/cat-broker/src/test/java/com/dianping/cat/broker/SingleTest.java index 1cb101539e22952f11ab5d5e5866781e29d5b563..db70dfb48f80c99ca95eb7c0b31de9baef36e0a4 100644 --- a/cat-broker/src/test/java/com/dianping/cat/broker/SingleTest.java +++ b/cat-broker/src/test/java/com/dianping/cat/broker/SingleTest.java @@ -12,18 +12,25 @@ public class SingleTest { public void test() throws Exception { while (true) { for (int i = 0; i < 10; i++) { - URL url = new URL(buildUrl(i)); - URLConnection URLconnection = url.openConnection(); - URLconnection.setRequestProperty("User-Agent", - "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon;)"); - - HttpURLConnection httpConnection = (HttpURLConnection) URLconnection; - int responseCode = httpConnection.getResponseCode(); - - if (responseCode == HttpURLConnection.HTTP_OK) { - System.out.println("ok"); - } else { - System.out.println(responseCode); + try { + URL url = new URL(buildUrl(i)); + URLConnection URLconnection = url.openConnection(); + + URLconnection.setConnectTimeout(500); + URLconnection.setReadTimeout(500); + URLconnection.setRequestProperty("User-Agent", + "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon;)"); + + HttpURLConnection httpConnection = (HttpURLConnection) URLconnection; + int responseCode = httpConnection.getResponseCode(); + + if (responseCode == HttpURLConnection.HTTP_OK) { + System.out.println("ok"); + } else { + System.out.println(responseCode); + } + } catch (Exception e) { + e.printStackTrace(); } } Thread.sleep(1000); @@ -33,28 +40,18 @@ public class SingleTest { private String buildUrl(int i) { StringBuilder sb = new StringBuilder(128); - sb.append("http://localhost:2765/broker-service/api/single?v=1&ts=123456&tu=http://j1.s1.dpfile.com/lib/1.0/cdn-perf/res/cdn_small.png/dnsLookup&d=1000&hs=200&ec=100"); + int hs = 200; + int ec = 100; + + if (i % 2 == 1) { + hs = 300; + ec = 200; + } + sb.append( + "http://localhost:2765/broker-service/api/single?v=1&ts=123456&tu=http://j1.s1.dpfile.com/lib/1.0/cdn-perf/res/cdn_small.png/dnsLookup&d=1000&hs=") + .append(hs).append("&ec=").append(ec); return sb.toString(); } - // @Test - // public void test2() throws Exception{ - // for (int i = 0; i < 1000; i++) { - // URL url = new URL("http://localhost:2281/cat/r/jsError?error=Script%20error.&file=&line=0×tamp=1371196520045"); - // URLConnection URLconnection = url.openConnection(); - // URLconnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon;)"); - // URLconnection.setRequestProperty("referer", "http://www.dianping.com/shop/2340226"); - // - // HttpURLConnection httpConnection = (HttpURLConnection) URLconnection; - // int responseCode = httpConnection.getResponseCode(); - // - // if (responseCode == HttpURLConnection.HTTP_OK) { - // } else { - // } - // Thread.sleep(100); - // } - - // } - } diff --git a/cat-home/src/main/java/com/dianping/cat/helper/TimeHelper.java b/cat-home/src/main/java/com/dianping/cat/helper/TimeHelper.java index e8d5074432f452ec3ca738fd2401274b6c388e03..3b2e04f5b0ea3829bdf91ab4aa12941dcb73de86 100644 --- a/cat-home/src/main/java/com/dianping/cat/helper/TimeHelper.java +++ b/cat-home/src/main/java/com/dianping/cat/helper/TimeHelper.java @@ -45,6 +45,21 @@ public class TimeHelper { return cal.getTime(); } + public static Date getCurrentDay(long timestamp) { + return getCurrentDay(timestamp, 0); + } + + public static Date getCurrentDay(long timestamp, int index) { + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(timestamp); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + cal.add(Calendar.DAY_OF_MONTH, index); + return cal.getTime(); + } + public static Date getCurrentHour() { Calendar cal = Calendar.getInstance(); diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/web/Handler.java b/cat-home/src/main/java/com/dianping/cat/report/page/web/Handler.java index 61249c00af94f19dcd45fb29089ac3f8eeb9f382..217e8ec656cafd294773483fba6e0a13adaf174e 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/web/Handler.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/web/Handler.java @@ -6,8 +6,10 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import javax.servlet.ServletException; @@ -21,15 +23,16 @@ import org.unidal.web.mvc.annotation.PayloadMeta; import com.dianping.cat.Constants; import com.dianping.cat.config.url.UrlPatternConfigManager; import com.dianping.cat.configuration.url.pattern.entity.PatternItem; -import com.dianping.cat.helper.TimeHelper; import com.dianping.cat.report.ReportPage; import com.dianping.cat.report.page.JsonBuilder; import com.dianping.cat.report.page.LineChart; import com.dianping.cat.report.page.PayloadNormalizer; import com.dianping.cat.report.page.PieChart; import com.dianping.cat.report.page.web.graph.WebGraphCreator; +import com.site.helper.Splitters; public class Handler implements PageHandler { + @Inject private JspViewer m_jspViewer; @@ -45,6 +48,74 @@ public class Handler implements PageHandler { @Inject private WebGraphCreator m_graphCreator; + private Pair, List> buildDisplayInfo(QueryEntity query, String title) { + Pair, List> charts = m_graphCreator.queryBaseInfo(query, title); + Map lineCharts = charts.getKey(); + List pieCharts = charts.getValue(); + + return new Pair, List>(lineCharts, pieCharts); + } + + private void buildInfoCharts(Model model, QueryEntity currentQuery, QueryEntity compareQuery) { + Map lineCharts = new LinkedHashMap(); + List pieCharts = new LinkedList(); + Pair, List> currentPair = buildDisplayInfo(currentQuery, "当前值"); + + lineCharts.putAll(currentPair.getKey()); + pieCharts.addAll(currentPair.getValue()); + + if (compareQuery != null) { + Pair, List> comparePair = buildDisplayInfo(compareQuery, "对比值"); + for (Entry entry : comparePair.getKey().entrySet()) { + LineChart linechart = entry.getValue(); + LineChart l = lineCharts.get(entry.getKey()); + + if (l != null) { + l.add(linechart.getSubTitles().get(0), linechart.getValueObjects().get(0)); + } + } + pieCharts.addAll(comparePair.getValue()); + model.setCompareStart(compareQuery.getStart()); + model.setCompareEnd(compareQuery.getEnd()); + } + for (Entry entry : lineCharts.entrySet()) { + if (WebGraphCreator.SUCESS_PERCENT.equals(entry.getKey())) { + LineChart linechart = entry.getValue(); + + linechart.setMinYlable(m_graphCreator.queryMinYlable(linechart.getValueObjects())); + linechart.setMaxYlabel(100.0); + } + } + model.setLineCharts(lineCharts); + model.setPieCharts(pieCharts); + } + + private Pair buildQueryEntities(Payload payload) { + Pair startPair = payload.getHistoryStartDatePair(); + Pair endPair = payload.getHistoryEndDatePair(); + List urls = Splitters.by(";").split(payload.getUrl()); + List channels = Splitters.by(";").split(payload.getChannel()); + List cities = Splitters.by(";").split(payload.getCity()); + String type = payload.getType(); + QueryEntity current = buildQueryEntity(startPair.getKey(), endPair.getKey(), urls.get(0), type, channels.get(0), + cities.get(0)); + QueryEntity compare = null; + + if (startPair.getValue() != null && endPair.getValue() != null && urls.size() == 2) { + compare = buildQueryEntity(startPair.getValue(), endPair.getValue(), urls.get(1), Constants.TYPE_INFO, + channels.get(1), cities.get(1)); + } + return new Pair(current, compare); + } + + private QueryEntity buildQueryEntity(Date start, Date end, String url, String type, String channel, String city) { + QueryEntity queryEntity = new QueryEntity(start, end, url); + + queryEntity.addPar("metricType", Constants.METRIC_USER_MONITOR).addPar("type", type).addPar("channel", channel) + .addPar("city", city); + return queryEntity; + } + @Override @PayloadMeta(Payload.class) @InboundActionMeta(name = "web") @@ -59,81 +130,41 @@ public class Handler implements PageHandler { Payload payload = ctx.getPayload(); normalize(model, payload); - Collection rules = m_patternManager.queryUrlPatternRules(); - - long start = payload.getHistoryStartDate().getTime(); - long end = payload.getHistoryEndDate().getTime(); - - start = start - start % TimeHelper.ONE_HOUR; - end = end - end % TimeHelper.ONE_HOUR; - - Date startDate = new Date(start); - Date endDate = new Date(end); - String type = payload.getType(); - String channel = payload.getChannel(); - String city = payload.getCity(); - Map pars = new LinkedHashMap(); - String url = payload.getUrl(); - - if (url == null && rules.size() > 0) { - PatternItem patternItem = new ArrayList(rules).get(0); - - url = patternItem.getName(); - payload.setGroup(patternItem.getGroup()); - payload.setUrl(url); - } - - pars.put("metricType", Constants.METRIC_USER_MONITOR); - pars.put("type", type); - pars.put("channel", channel); - pars.put("city", city); - + Pair queryEntities = buildQueryEntities(payload); + QueryEntity currentQuery = queryEntities.getKey(); + QueryEntity compareQuery = queryEntities.getValue(); Action action = payload.getAction(); switch (action) { case VIEW: - if (url != null) { - if (Constants.TYPE_INFO.equals(type)) { - Pair, List> charts = m_graphCreator.queryBaseInfo(startDate, endDate, - url, pars); - Map lineCharts = charts.getKey(); - List pieCharts = charts.getValue(); - - model.setLineCharts(lineCharts); - model.setPieCharts(pieCharts); - } else { - Pair pair = m_graphCreator.queryErrorInfo(startDate, endDate, url, pars); - - model.setLineChart(pair.getKey()); - model.setPieChart(pair.getValue()); - } + if (Constants.TYPE_INFO.equals(payload.getType())) { + buildInfoCharts(model, currentQuery, compareQuery); + } else { + Pair pair = m_graphCreator.queryErrorInfo(currentQuery); + + model.setLineChart(pair.getKey()); + model.setPieChart(pair.getValue()); } - model.setStart(startDate); - model.setEnd(endDate); - model.setPattermItems(rules); + model.setStart(currentQuery.getStart()); + model.setEnd(currentQuery.getEnd()); + model.setPattermItems(m_patternManager.queryUrlPatternRules()); model.setAction(Action.VIEW); - model.setPage(ReportPage.WEB); model.setCityInfo(m_cityManager.getCityInfo()); break; - case JSON: - if (url != null) { - Map jsonObjs = new HashMap(); + Map jsonObjs = new HashMap(); + if (Constants.TYPE_INFO.equals(payload.getType())) { + Pair, List> currentPair = buildDisplayInfo(currentQuery, "当前值"); - if (Constants.TYPE_INFO.equals(type)) { - Pair, List> charts = m_graphCreator.queryBaseInfo(startDate, endDate, - url, pars); + jsonObjs.put("lineCharts", currentPair.getKey()); + jsonObjs.put("pieCharts", currentPair.getValue()); + } else { + Pair pair = m_graphCreator.queryErrorInfo(currentQuery); - jsonObjs.put("lineCharts", charts.getKey()); - jsonObjs.put("pieCharts", charts.getValue()); - } else { - Pair pair = m_graphCreator.queryErrorInfo(startDate, endDate, url, pars); - - jsonObjs.put("lineChart", pair.getKey()); - jsonObjs.put("pieChart", pair.getValue()); - } - model.setJson(new JsonBuilder().toJson(jsonObjs)); + jsonObjs.put("lineChart", pair.getKey()); + jsonObjs.put("pieChart", pair.getValue()); } + model.setJson(new JsonBuilder().toJson(jsonObjs)); break; } @@ -144,7 +175,68 @@ public class Handler implements PageHandler { private void normalize(Model model, Payload payload) { model.setPage(ReportPage.WEB); + Collection rules = m_patternManager.queryUrlPatternRules(); + String url = payload.getUrl(); + + if (url == null && rules.size() > 0) { + PatternItem patternItem = new ArrayList(rules).get(0); + + url = patternItem.getName(); + payload.setGroup(patternItem.getGroup()); + payload.setUrl(url); + } m_normalizePayload.normalize(model, payload); } + + public class QueryEntity { + private String m_url; + + private Date m_start; + + private Date m_end; + + private Map m_pars = new HashMap(); + + public QueryEntity(Date start, Date end, String url) { + m_start = start; + m_end = end; + m_url = url; + } + + public QueryEntity addPar(String par, String value) { + m_pars.put(par, value); + return this; + } + + public Date getEnd() { + return m_end; + } + + public Map getPars() { + return m_pars; + } + + public Date getStart() { + return m_start; + } + + public String getType() { + return m_pars.get("type"); + } + + public String getUrl() { + return m_url; + } + + public QueryEntity setEnd(Date end) { + m_end = end; + return this; + } + + public QueryEntity setStart(Date start) { + m_start = start; + return this; + } + } } diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/web/Model.java b/cat-home/src/main/java/com/dianping/cat/report/page/web/Model.java index c866e49836648d35ad9eca4dc59d61f4e09731df..5b51f6feb80cb0764fb60129fea3c9b21aa15b08 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/web/Model.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/web/Model.java @@ -31,6 +31,10 @@ public class Model extends AbstractReportModel { private Date m_end; + private Date m_compareStart; + + private Date m_compareEnd; + private String m_cityInfo; private String m_json; @@ -47,6 +51,14 @@ public class Model extends AbstractReportModel { return m_cityInfo; } + public Date getCompareEnd() { + return m_compareEnd; + } + + public Date getCompareStart() { + return m_compareStart; + } + @Override public Action getDefaultAction() { return Action.VIEW; @@ -121,6 +133,14 @@ public class Model extends AbstractReportModel { m_cityInfo = cityInfo; } + public void setCompareEnd(Date compareEnd) { + m_compareEnd = compareEnd; + } + + public void setCompareStart(Date compareStart) { + m_compareStart = compareStart; + } + public void setEnd(Date end) { m_end = end; } diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/web/Payload.java b/cat-home/src/main/java/com/dianping/cat/report/page/web/Payload.java index 59a267c1fd2b798c2067c0c86b0b1a7ee80cf8b9..be2753f7b7d9d0da5114a084cf7da35f014d5f7c 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/web/Payload.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/web/Payload.java @@ -3,9 +3,11 @@ package com.dianping.cat.report.page.web; import java.text.SimpleDateFormat; import java.util.Date; +import org.unidal.tuple.Pair; import org.unidal.web.mvc.ActionContext; import org.unidal.web.mvc.payload.annotation.FieldMeta; +import com.dianping.cat.Cat; import com.dianping.cat.Constants; import com.dianping.cat.helper.TimeHelper; import com.dianping.cat.report.ReportPage; @@ -24,7 +26,7 @@ public class Payload extends AbstractReportPayload { private String m_city = "上海市"; @FieldMeta("channel") - private String m_channel; + private String m_channel = ""; @FieldMeta("group") private String m_group; @@ -55,29 +57,68 @@ public class Payload extends AbstractReportPayload { return m_group; } - public Date getHistoryEndDate() { + private Date generateDate(String time, long start) { + Date date = null; + String[] times = time.split(":"); + + if (times.length == 2) { + int hour = Integer.parseInt(times[0]); + int minute = Integer.parseInt(times[1]); + if (minute > 0) { + hour += 1; + } + + date = new Date(TimeHelper.getCurrentDay(start, 0).getTime() + hour * TimeHelper.ONE_HOUR); + if (date.equals(TimeHelper.getCurrentDay(start, 1))) { + date = new Date(date.getTime() - TimeHelper.ONE_MINUTE); + } + } else { + date = TimeHelper.getCurrentHour(1); + } + return date; + } + + public Pair getHistoryEndDatePair() { + Date currentEnd = TimeHelper.getCurrentHour(1); + Date compareEnd = null; + try { if (m_customEnd != null && m_customEnd.length() > 0) { - return m_format.parse(m_customEnd); - } else { - return TimeHelper.getCurrentHour(1); + String[] ends = m_customEnd.split(";"); + Pair startDatePair = getHistoryStartDatePair(); + long start = startDatePair.getKey().getTime(); + currentEnd = generateDate(ends[0], start); + + if (ends.length == 2) { + start = startDatePair.getValue().getTime(); + compareEnd = generateDate(ends[1], start); + } } } catch (Exception e) { - return TimeHelper.getCurrentHour(1); + Cat.logError(e); } + return new Pair(currentEnd, compareEnd); } - public Date getHistoryStartDate() { + public Pair getHistoryStartDatePair() { + Date currentStart = TimeHelper.getCurrentDay(); + Date compareStart = null; + try { if (m_customStart != null && m_customStart.length() > 0) { - - return m_format.parse(m_customStart); - } else { - return TimeHelper.getCurrentHour(-2); + String[] starts = m_customStart.split(";"); + Date current = m_format.parse(starts[0]); + currentStart = new Date(current.getTime() - current.getTime() % TimeHelper.ONE_HOUR); + + if (starts.length == 2) { + Date compare = m_format.parse(starts[1]); + compareStart = new Date(compare.getTime() - compare.getTime() % TimeHelper.ONE_HOUR); + } } } catch (Exception e) { - return TimeHelper.getCurrentHour(-2); + Cat.logError(e); } + return new Pair(currentStart, compareStart); } @Override diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/web/graph/WebGraphCreator.java b/cat-home/src/main/java/com/dianping/cat/report/page/web/graph/WebGraphCreator.java index 8e7e19c8952c3e843a49320a9f5524e12a72eed9..8c3fc1718160dbf636d38be4f3d79cd612a7450d 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/web/graph/WebGraphCreator.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/web/graph/WebGraphCreator.java @@ -1,6 +1,9 @@ package com.dianping.cat.report.page.web.graph; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; @@ -21,16 +24,17 @@ import com.dianping.cat.report.page.LineChart; import com.dianping.cat.report.page.PieChart; import com.dianping.cat.report.page.PieChart.Item; import com.dianping.cat.report.page.model.metric.MetricReportMerger; +import com.dianping.cat.report.page.web.Handler.QueryEntity; public class WebGraphCreator extends AbstractGraphCreator { - private static final String COUNT = "每分钟访问量(次数)"; + private static final String COUNT = "访问量(次数/5分钟)"; - private static final String AVG = "每分钟响应时间(ms)"; + private static final String AVG = "平均响应时间(毫秒/5分钟)"; - private static final String SUCESS_PERCENT = "每分钟调用成功率(%)"; + public static final String SUCESS_PERCENT = "访问成功率(%/5分钟)"; - private List buildDetailPieChart(MetricReport report) { + private List buildDetailPieChart(MetricReport report, String title) { Map statics = report.getStatistics(); List charts = new ArrayList(); @@ -47,107 +51,106 @@ public class WebGraphCreator extends AbstractGraphCreator { item.setTitle(tmp.getId()); items.add(item); } - chart.setTitle(entry.getKey()); + chart.setTitle(entry.getKey() + "【" + title + "】"); chart.addItems(items); charts.add(chart); } return charts; } - public Pair buildErrorChartData(final Map datas, Date startDate, - Date endDate, final Map dataWithOutFutures) { + public Pair buildCodeChartData(final Map dataWithOutFutures, String type) { LineChart lineChart = new LineChart(); - int step = m_dataExtractor.getStep(); - lineChart.setStart(startDate); - lineChart.setStep(step * TimeHelper.ONE_MINUTE); + lineChart.setUnit(""); + lineChart.setHtmlTitle(type + "平均分布(个/5分钟)"); + PieChart pieChart = new PieChart(); List items = new ArrayList(); pieChart.addItems(items); - for (Entry entry : dataWithOutFutures.entrySet()) { + for (Entry entry : dataWithOutFutures.entrySet()) { String key = entry.getKey(); - double[] value = entry.getValue(); - Map all = convertToMap(datas.get(key), startDate, 1); - Map current = convertToMap(dataWithOutFutures.get(key), startDate, step); - - addLastMinuteData(current, all, m_lastMinute, endDate); - lineChart.setSize(value.length); - lineChart.add(entry.getKey(), current); + Double[] value = entry.getValue(); - double sum = computeSum(current); + lineChart.add(key, value); + double sum = computeSum(value); items.add(new Item().setTitle(entry.getKey()).setNumber(sum)); } return new Pair(lineChart, pieChart); } - private Map buildInfoChartData(final Map datas, Date startDate, Date endDate, - final Map dataWithOutFutures) { + private Map buildInfoChartData(final Map dataWithOutFutures, Date startDate, + Date endDate, String title) { Map charts = new LinkedHashMap(); - int step = m_dataExtractor.getStep(); - - for (Entry entry : dataWithOutFutures.entrySet()) { + for (Entry entry : dataWithOutFutures.entrySet()) { String key = entry.getKey(); - double[] value = entry.getValue(); + Double[] value = entry.getValue(); LineChart lineChart = new LineChart(); lineChart.setId(key); + lineChart.setUnit(""); lineChart.setTitle(key); - lineChart.setStart(startDate); - lineChart.setSize(value.length); - lineChart.setStep(step * TimeHelper.ONE_MINUTE); - - Map all = convertToMap(datas.get(key), startDate, 1); - Map current = convertToMap(dataWithOutFutures.get(key), startDate, step); - - addLastMinuteData(current, all, m_lastMinute, endDate); - lineChart.add(entry.getKey(), current); + lineChart.setHtmlTitle(key); + lineChart.add(title, value); charts.put(key, lineChart); } return charts; } - public double computeSum(Map data) { + public double computeSum(Double[] data) { double result = 0; - for (double d : data.values()) { - result = result + d; + for (int i = 0; i < data.length; i++) { + if (data[i] != null) { + result = result + data[i]; + } } return result; } - private Map fetchMetricCodeInfo(MetricReport report) { + private Map fetchMetricCodeInfo(MetricReport report) { Map items = report.getMetricItems(); - Map datas = new LinkedHashMap(); + Map datas = new LinkedHashMap(); for (Entry item : items.entrySet()) { String id = item.getKey(); int index = id.indexOf("|"); String key = id.substring(index + 1); Map segments = item.getValue().getSegments(); - double[] data = datas.get(key); + Double[] data = datas.get(key); if (data == null) { - data = new double[60]; + data = new Double[12]; datas.put(key, data); } for (Segment segment : segments.values()) { - int count = segment.getCount(); - int minute = segment.getId(); - - data[minute] = count; + dataInc(data, segment.getId() / 5, segment.getCount()); } } return datas; } - private Map fetchMetricInfoData(MetricReport report) { - Map data = new LinkedHashMap(); + private void dataInc(Double[] datas, int index, double value) { + if (datas[index] != null) { + datas[index] += value; + } else { + datas[index] = value; + } + } + + private Map fetchMetricInfoData(MetricReport report) { + Map data = new LinkedHashMap(); + + Double[] count = new Double[12]; + Double[] avg = new Double[12]; + Double[] avgCount = new Double[12]; + Double[] avgSum = new Double[12]; + Double[] error = new Double[12]; + Double[] successPercent = new Double[12]; - double[] count = new double[60]; - double[] avg = new double[60]; - double[] error = new double[60]; - double[] successPercent = new double[60]; + for (int i = 0; i < successPercent.length; i++) { + successPercent[i] = 100.0; + } data.put(COUNT, count); data.put(AVG, avg); @@ -160,77 +163,137 @@ public class WebGraphCreator extends AbstractGraphCreator { Map segments = item.getValue().getSegments(); for (Segment segment : segments.values()) { - int id = segment.getId(); + int id = segment.getId() / 5; if (key.endsWith(Constants.HIT)) { - count[id] = segment.getCount(); + dataInc(count, id, segment.getCount()); } else if (key.endsWith(Constants.ERROR)) { - error[id] = segment.getCount(); + dataInc(error, id, segment.getCount()); } else if (key.endsWith(Constants.AVG)) { - avg[id] = segment.getAvg(); + dataInc(avgCount, id, segment.getCount()); + dataInc(avgSum, id, segment.getSum()); } } } - for (int i = 0; i < 60; i++) { - double sum = count[i]; - double success = count[i] - error[i]; + for (int i = 0; i < 12; i++) { + if (avgSum[i] != null && avgCount[i] != null) { + avg[i] = avgSum[i] / avgCount[i]; + } + } - if (sum > 0) { - successPercent[i] = success / sum * 100.0; - } else { - successPercent[i] = 100; + for (int i = 0; i < 12; i++) { + if (count[i] != null) { + double sum = count[i]; + double success = count[i] - (error[i] != null ? error[i] : 0.0); + + if (sum > 0) { + successPercent[i] = success / sum * 100.0; + } else { + successPercent[i] = 100.0; + } } } return data; } - private Map prepareAllData(MetricReport all, String url, Map pars, Date startDate, - Date endDate) { - long start = startDate.getTime(), end = endDate.getTime(); - int totalSize = (int) ((end - start) / TimeHelper.ONE_MINUTE); - Map sourceValue = new LinkedHashMap(); - int index = 0; - String type = pars.get("type"); + protected void mergeValue(Map all, Map item, int size, int index) { + for (Entry entry : item.entrySet()) { + String key = entry.getKey(); + Double[] value = entry.getValue(); + Double[] result = all.get(key); + + if (result == null) { + result = new Double[size]; + all.put(key, result); + if (SUCESS_PERCENT.equals(key)) { + for (int i = 0; i < size; i++) { + result[i] = 100.0; + } + } + } + if (value != null) { + int length = value.length; + int pos = index; + for (int i = 0; i < length && pos < size; i++, pos++) { + result[pos] = value[i]; + } + } + } + } + + private Map prepareAllData(MetricReport all, QueryEntity query) { + long start = query.getStart().getTime(), end = query.getEnd().getTime(); + Date currentDay = TimeHelper.getCurrentDay(start); + int totalSize = queryDuration(currentDay, 288); + Map sourceValue = new LinkedHashMap(); + String type = query.getPars().get("type"); MetricReportMerger merger = new MetricReportMerger(all); for (; start < end; start += TimeHelper.ONE_HOUR) { - MetricReport report = m_metricReportService.queryUserMonitorReport(url, pars, new Date(start)); + MetricReport report = m_metricReportService.queryUserMonitorReport(query.getUrl(), query.getPars(), new Date( + start)); + int index = (int) ((start - currentDay.getTime()) / (TimeHelper.ONE_MINUTE * 5)); if (Constants.TYPE_INFO.equals(type)) { - Map currentValues = fetchMetricInfoData(report); + Map currentValues = fetchMetricInfoData(report); - mergeMap(sourceValue, currentValues, totalSize, index); + mergeValue(sourceValue, currentValues, totalSize, index); report.accept(merger); } else { - Map currentValues = fetchMetricCodeInfo(report); + Map currentValues = fetchMetricCodeInfo(report); - mergeMap(sourceValue, currentValues, totalSize, index); + mergeValue(sourceValue, currentValues, totalSize, index); } - index++; } return sourceValue; } - public Pair, List> queryBaseInfo(Date startDate, Date endDate, String url, - Map pars) { - MetricReport report = new MetricReport(url); - Map oldCurrentValues = prepareAllData(report, url, pars, startDate, endDate); - Map allCurrentValues = m_dataExtractor.extract(oldCurrentValues); - Map dataWithOutFutures = removeFutureData(endDate, allCurrentValues); + public Pair, List> queryBaseInfo(QueryEntity queryEntity, String title) { + MetricReport report = new MetricReport(queryEntity.getUrl()); + Map oldCurrentValues = prepareAllData(report, queryEntity); + Map lineCharts = buildInfoChartData(oldCurrentValues, queryEntity.getStart(), + queryEntity.getEnd(), title); + List pieCharts = buildDetailPieChart(report, title); - Map lineCharts = buildInfoChartData(oldCurrentValues, startDate, endDate, dataWithOutFutures); - List pieCharts = buildDetailPieChart(report); return new Pair, List>(lineCharts, pieCharts); } - public Pair queryErrorInfo(Date startDate, Date endDate, String url, Map pars) { - MetricReport report = new MetricReport(url); - Map oldCurrentValues = prepareAllData(report, url, pars, startDate, endDate); - Map allCurrentValues = m_dataExtractor.extract(oldCurrentValues); - Map dataWithOutFutures = removeFutureData(endDate, allCurrentValues); + private int queryDuration(Date period, int defaultValue) { + Calendar cal = Calendar.getInstance(); + + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + + if (cal.getTime().equals(period)) { + long start = cal.getTimeInMillis(); + long current = System.currentTimeMillis(); + int length = (int) (current - current % 300000 - start) / 300000; - return buildErrorChartData(oldCurrentValues, startDate, endDate, dataWithOutFutures); + return length < 0 ? 0 : length; + } + return defaultValue; + } + + public Pair queryErrorInfo(QueryEntity queryEntity) { + MetricReport report = new MetricReport(queryEntity.getUrl()); + Map oldCurrentValues = prepareAllData(report, queryEntity); + + return buildCodeChartData(oldCurrentValues, queryEntity.getType()); } + public double queryMinYlable(final List datas) { + double min = Double.MAX_VALUE; + + for (Double[] data : datas) { + List dataList = Arrays.asList(data); + double tmp = Collections.min(dataList); + if (min > tmp) { + min = tmp; + } + } + return min; + } } diff --git a/cat-home/src/main/webapp/js/baseGraph.js b/cat-home/src/main/webapp/js/baseGraph.js index 936c9c3483ed3844973a0727a931503fefda411a..4d183294eed2d1222e8219e5afc3f69922b46d6d 100644 --- a/cat-home/src/main/webapp/js/baseGraph.js +++ b/cat-home/src/main/webapp/js/baseGraph.js @@ -171,7 +171,7 @@ function graphMetricChart(container, data) { }); } -function parseMetricLineDataForApp(data) { +function parseMetricLineDataForDay(data) { var res = []; data.subTitles.forEach(function(title, i) { var series = {} @@ -182,7 +182,7 @@ function parseMetricLineDataForApp(data) { return res; } -function graphMetricChartForApp(container, data, datePair) { +function graphMetricChartForDay(container, data, datePair) { Highcharts.setOptions({ global : { useUTC : true @@ -190,7 +190,7 @@ function graphMetricChartForApp(container, data, datePair) { }); var ylabelMin = data.minYlabel; var ylabelMax = data.maxYlabel; - var _data = parseMetricLineDataForApp(data); + var _data = parseMetricLineDataForDay(data); $(container).highcharts( { chart : { diff --git a/cat-home/src/main/webapp/jsp/report/app/linechart.jsp b/cat-home/src/main/webapp/jsp/report/app/linechart.jsp index 3b1ead86a7e3ee699ca2199ef316a0a870890f28..06b3a2f6419c9ec641c5fbcefa26ee9021f42dc5 100644 --- a/cat-home/src/main/webapp/jsp/report/app/linechart.jsp +++ b/cat-home/src/main/webapp/jsp/report/app/linechart.jsp @@ -261,7 +261,7 @@ } var data = ${model.lineChart.jsonString}; - graphMetricChartForApp(document + graphMetricChartForDay(document .getElementById('${model.lineChart.id}'), data, datePair); }); diff --git a/cat-home/src/main/webapp/jsp/report/app/speed.jsp b/cat-home/src/main/webapp/jsp/report/app/speed.jsp index 29e328ad58276dfc2e33baabf52f86b03e7d1c1c..e0aec874d695c4a6a9e3172ba4a83ac080aca9d0 100644 --- a/cat-home/src/main/webapp/jsp/report/app/speed.jsp +++ b/cat-home/src/main/webapp/jsp/report/app/speed.jsp @@ -173,7 +173,7 @@ var data = ${model.appSpeedDisplayInfo.lineChart.jsonString}; - graphMetricChartForApp(document.getElementById('${model.appSpeedDisplayInfo.lineChart.id}'), + graphMetricChartForDay(document.getElementById('${model.appSpeedDisplayInfo.lineChart.id}'), data, datePair); }); diff --git a/cat-home/src/main/webapp/jsp/report/web/web.jsp b/cat-home/src/main/webapp/jsp/report/web/web.jsp index fb22b7f032532c1027c19ed7472d4d62943e77b6..688ce5f8b16474df1c44bcfb181dd34520fe74e3 100644 --- a/cat-home/src/main/webapp/jsp/report/web/web.jsp +++ b/cat-home/src/main/webapp/jsp/report/web/web.jsp @@ -17,6 +17,28 @@ -
- - - - - - - -
- 组 URL - 省份 城市 运营商 查询类型 -
开始时间 -
- - -
结束时间 -
- - -
- -
- - -
- -
-
-
-
-
- -
-
${item.title}
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
- - - - - - -
+<%@include file="webDetail.jsp"%> + diff --git a/cat-home/src/main/webapp/jsp/report/web/webDetail.jsp b/cat-home/src/main/webapp/jsp/report/web/webDetail.jsp new file mode 100644 index 0000000000000000000000000000000000000000..97977d76d50028e40dd2b75ca4a3fc53250394f6 --- /dev/null +++ b/cat-home/src/main/webapp/jsp/report/web/webDetail.jsp @@ -0,0 +1,117 @@ +<%@ page contentType="text/html; charset=utf-8"%> +
+ + + + + + + +
+
+ +
结束 +
+ + +
+ 组  URL + 省份 城市 +
+ 运营商 + 查询类型 +   +
+ + + + + + + + + +
+ +
+
+
+
+
+ +
+
${item.title}
+
+
+
+
+ +
+
+
+
+ + + + + + +
\ No newline at end of file diff --git a/script/Cat.sql b/script/Cat.sql index bc31332414671037a07aa1954a85c49a52f2c16f..03384989f3e82024b2866b93ca147b7a2ebc8000 100644 --- a/script/Cat.sql +++ b/script/Cat.sql @@ -353,7 +353,7 @@ CREATE TABLE `app_command_data_1` ( `city` smallint NOT NULL COMMENT '城市', `operator` tinyint NOT NULL COMMENT '运营商', `network` tinyint NOT NULL COMMENT '网络类型', - `app_version` smallint NOT NULL COMMENT '版本', + `app_version` int NOT NULL COMMENT '版本', `connect_type` tinyint NOT NULL COMMENT '访问类型,是否长连接', `code` smallint NOT NULL COMMENT '返回码', `platform` tinyint NOT NULL COMMENT '平台', @@ -374,7 +374,7 @@ CREATE TABLE `app_speed_data_1` ( `city` smallint NOT NULL COMMENT '城市', `operator` tinyint NOT NULL COMMENT '运营商', `network` tinyint NOT NULL COMMENT '网络类型', - `app_version` smallint NOT NULL COMMENT '版本', + `app_version` int NOT NULL COMMENT '版本', `platform` tinyint NOT NULL COMMENT '平台', `access_number` bigint NOT NULL COMMENT '访问量', `slow_access_number` bigint NOT NULL COMMENT '慢用户访问量',