diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/controller/AnalysisResultController.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/controller/AnalysisResultController.java index 8d31b146ab5a412e9a3b2a586ccd2be026d942e9..1622c05dceaba41943cc2090309828aca650a431 100644 --- a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/controller/AnalysisResultController.java +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/controller/AnalysisResultController.java @@ -2,11 +2,10 @@ package com.ai.cloud.skywalking.web.controller; import com.ai.cloud.skywalking.web.common.BaseController; import com.ai.cloud.skywalking.web.dto.CallChainTree; -import com.ai.cloud.skywalking.web.dto.LoginUserInfo; +import com.ai.cloud.skywalking.web.dto.TypicalCallTree; import com.ai.cloud.skywalking.web.service.inter.IAnalysisResultService; import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; -import com.google.gson.JsonObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -16,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; +import java.util.List; /** * Created by xin on 16-4-5. @@ -47,13 +47,13 @@ public class AnalysisResultController extends BaseController { @PathVariable("analyDate") String analyDate) { JSONObject result = new JSONObject(); try { - // LoginUserInfo userInfo = fetchLoginUserInfoFromSession(request); + // LoginUserInfo userInfo = fetchLoginUserInfoFromSession(request); CallChainTree callChainTree = analysisResultService. fetchAnalysisResult(treeId, analyType, analyDate); result.put("code", "200"); if (callChainTree != null) { result.put("result", new Gson().toJson(callChainTree)); - }else{ + } else { result.put("result", "{}"); } } catch (Exception e) { @@ -64,4 +64,28 @@ public class AnalysisResultController extends BaseController { } return result.toJSONString(); } + + @RequestMapping(value = "/load/{treeId}/{analyDate}", produces = "application/json; charset=UTF-8") + @ResponseBody + public String loadTypicalCallTree(HttpServletRequest request, + @PathVariable("treeId") String treeId, + @PathVariable("analyDate") String analyDate) { + JSONObject result = new JSONObject(); + + try { + List typicalCallTrees = analysisResultService.fetchTypicalCallTrees(treeId, analyDate); + result.put("code", "200"); + if (typicalCallTrees != null) { + result.put("result", new Gson().toJson(typicalCallTrees)); + } else { + result.put("result", "{}"); + } + } catch (Exception e) { + logger.error("Failed to load treeId[{}], anlyDate:[{}]", treeId, analyDate); + e.printStackTrace(); + result.put("code", "500"); + result.put("message", "Fatal error"); + } + return result.toJSONString(); + } } diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/impl/CallChainTreeDao.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/impl/CallChainTreeDao.java index 808a2a3fa7e0c4814f34d13110931cc8dd511c87..840a506b5dd4d15b4c7ae3fd25572b0bf6659556 100644 --- a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/impl/CallChainTreeDao.java +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/impl/CallChainTreeDao.java @@ -23,7 +23,6 @@ import org.springframework.stereotype.Repository; import java.io.IOException; import java.util.Calendar; -import java.util.Collections; import java.util.Map; @Repository @@ -36,10 +35,6 @@ public class CallChainTreeDao implements ICallChainTreeDao { @Override public AnlyResult queryEntranceAnlyResult(String entranceColumnName, String treeId) throws IOException { - String columnName = entranceColumnName; - if (entranceColumnName.lastIndexOf(":") != -1) { - columnName = entranceColumnName.substring(0, entranceColumnName.length() - 1); - } Table table = hBaseUtils.getConnection().getTable(TableName.valueOf("sw-chain-1month-summary")); Get get = new Get(treeId.getBytes()); Result result = table.get(get); @@ -48,19 +43,17 @@ public class CallChainTreeDao implements ICallChainTreeDao { return new AnlyResult(calendar.get(Calendar.YEAR) + "", (calendar.get(Calendar.MONTH) + 1) + ""); } AnlyResult anlyResult = null; - Cell cell = result.getColumnLatestCell("chain_summary".getBytes(), columnName.getBytes()); - if (cell != null) { - String anlyResultStr = Bytes.toString(cell.getValueArray(), - cell.getValueOffset(), cell.getValueLength()); - logger.debug("traceId: {} , entranceColumnName : {}, anlyResultStr : {}", - treeId, columnName, anlyResultStr); - JsonObject jsonObject = (JsonObject) new JsonParser().parse(anlyResultStr); - Map resultMap = new Gson().fromJson(jsonObject.getAsJsonObject("summaryValueMap"), - new TypeToken>() { - }.getType()); - anlyResult = resultMap.get((Calendar.getInstance().get(Calendar.MONTH) + 1) + ""); - } + Cell cell = result.getColumnLatestCell("chain_summary".getBytes(), entranceColumnName.getBytes()); + String anlyResultStr = Bytes.toString(cell.getValueArray(), + cell.getValueOffset(), cell.getValueLength()); + logger.debug("traceId: {} , entranceColumnName : {}, anlyResultStr : {}", + treeId, entranceColumnName, anlyResultStr); + JsonObject jsonObject = (JsonObject) new JsonParser().parse(anlyResultStr); + Map resultMap = new Gson().fromJson(jsonObject.getAsJsonObject("summaryValueMap"), + new TypeToken>() { + }.getType()); + anlyResult = resultMap.get((Calendar.getInstance().get(Calendar.MONTH) + 1) + ""); if (anlyResult == null) { anlyResult = new AnlyResult(); } diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/impl/TypicalCallTreeDaoImpl.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/impl/TypicalCallTreeDaoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..bdb733017420bdc51416692bd1fa03b1f4b1fc81 --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/impl/TypicalCallTreeDaoImpl.java @@ -0,0 +1,59 @@ +package com.ai.cloud.skywalking.web.dao.impl; + +import com.ai.cloud.skywalking.web.dao.inter.ITypicalCallTreeDao; +import com.ai.cloud.skywalking.web.dto.TypicalCallTree; +import com.ai.cloud.skywalking.web.dto.TypicalCallTreeNode; +import com.ai.cloud.skywalking.web.util.HBaseUtils; +import com.alibaba.fastjson.JSONArray; +import org.apache.hadoop.hbase.Cell; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.util.Bytes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.io.IOException; + +/** + * Created by xin on 16-4-28. + */ +@Repository +public class TypicalCallTreeDaoImpl implements ITypicalCallTreeDao { + + @Autowired + private HBaseUtils hBaseUtils; + + @Override + public String[] queryAllCombineCallChainTreeIds(String rowKey) throws IOException { + Table table = hBaseUtils.getConnection().getTable(TableName.valueOf("sw-treeId-cid-mapping")); + Get g = new Get(Bytes.toBytes(rowKey)); + + Result r = table.get(g); + if (r.rawCells().length == 0) { + return null; + } + Cell cell = r.getColumnLatestCell("cids".getBytes(), "been_merged_cid".getBytes()); + JSONArray result = JSONArray.parseArray(Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); + return result.toArray(new String[result.size()]); + } + + @Override + public TypicalCallTree queryCallChainTree(String callTreeId) throws IOException { + Table table = hBaseUtils.getConnection().getTable(TableName.valueOf("sw-chain-detail")); + Get g = new Get(Bytes.toBytes(callTreeId)); + + Result r = table.get(g); + if (r.rawCells().length == 0) { + return null; + } + TypicalCallTree callTree = new TypicalCallTree(callTreeId); + for (Cell cell : r.rawCells()) { + String levelId = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); + String viewPoint = Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); + callTree.addNode(new TypicalCallTreeNode(levelId, viewPoint)); + } + return callTree; + } +} diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/inter/ITypicalCallTreeDao.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/inter/ITypicalCallTreeDao.java new file mode 100644 index 0000000000000000000000000000000000000000..56aaa40e4b6adb81c4b80f3b0b02d39a24752224 --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dao/inter/ITypicalCallTreeDao.java @@ -0,0 +1,14 @@ +package com.ai.cloud.skywalking.web.dao.inter; + +import com.ai.cloud.skywalking.web.dto.TypicalCallTree; + +import java.io.IOException; + +/** + * Created by xin on 16-4-28. + */ +public interface ITypicalCallTreeDao { + String[] queryAllCombineCallChainTreeIds(String rowKey) throws IOException; + + TypicalCallTree queryCallChainTree(String callTreeId) throws IOException; +} diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/CallChainTreeNode.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/CallChainTreeNode.java index f217fee8fb08754706e2bce8b69c9f77595f424e..f8db878e5875e27279e9038840e0e37632a555a6 100644 --- a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/CallChainTreeNode.java +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/CallChainTreeNode.java @@ -1,6 +1,7 @@ package com.ai.cloud.skywalking.web.dto; import com.ai.cloud.skywalking.web.util.StringUtil; +import com.ai.cloud.skywalking.web.util.TokenGenerator; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -13,6 +14,7 @@ import java.util.Map; */ public class CallChainTreeNode { + private String nodeToken; private String traceLevelId; private String viewPoint; private AnlyResult anlyResult; @@ -20,6 +22,7 @@ public class CallChainTreeNode { public CallChainTreeNode(String qualifierStr, String valueStr, String loadKey) { traceLevelId = qualifierStr.substring(0, qualifierStr.indexOf("@")); viewPoint = qualifierStr.substring(qualifierStr.indexOf("@") + 1); + nodeToken = TokenGenerator.generate(traceLevelId + ":" + viewPoint); JsonObject jsonObject = (JsonObject) new JsonParser().parse(valueStr); Map resultMap = new Gson().fromJson(jsonObject.getAsJsonObject("summaryValueMap"), new TypeToken>() { @@ -44,4 +47,8 @@ public class CallChainTreeNode { + viewPoint.substring(viewPoint.length() - 50); } } + + public String getNodeToken() { + return nodeToken; + } } diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/TypicalCallTree.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/TypicalCallTree.java new file mode 100644 index 0000000000000000000000000000000000000000..94943a8cd6b43ac8dbf49f8dbd39e8bc15dd7066 --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/TypicalCallTree.java @@ -0,0 +1,22 @@ +package com.ai.cloud.skywalking.web.dto; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by xin on 16-4-28. + */ +public class TypicalCallTree { + private String callTreeId; + private List treeNodes; + + + public TypicalCallTree(String callTreeId) { + this.callTreeId = callTreeId; + this.treeNodes = new ArrayList(); + } + + public void addNode(TypicalCallTreeNode typicalCallTreeNode) { + this.treeNodes.add(typicalCallTreeNode); + } +} diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/TypicalCallTreeNode.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/TypicalCallTreeNode.java new file mode 100644 index 0000000000000000000000000000000000000000..d56fbd777575ceb1601b30e32b9913c49ebe6788 --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/dto/TypicalCallTreeNode.java @@ -0,0 +1,19 @@ +package com.ai.cloud.skywalking.web.dto; + +import com.ai.cloud.skywalking.web.util.TokenGenerator; + +/** + * Created by xin on 16-4-28. + */ +public class TypicalCallTreeNode { + private String nodeToken; + private String levelId; + private String viewpoint; + + + public TypicalCallTreeNode(String levelId, String viewPoint) { + this.levelId = levelId; + this.viewpoint = viewPoint; + this.nodeToken = TokenGenerator.generate(levelId + ":" + viewPoint); + } +} diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/service/impl/AnalysisResultService.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/service/impl/AnalysisResultService.java index 736905ea000b395c0e43585a5b91ed25146a2c14..74c291dfd87fd7f5776b2501243618f10e1a4e2e 100644 --- a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/service/impl/AnalysisResultService.java +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/service/impl/AnalysisResultService.java @@ -1,8 +1,10 @@ package com.ai.cloud.skywalking.web.service.impl; import com.ai.cloud.skywalking.web.dao.inter.ICallChainTreeDao; +import com.ai.cloud.skywalking.web.dao.inter.ITypicalCallTreeDao; import com.ai.cloud.skywalking.web.dto.CallChainTree; import com.ai.cloud.skywalking.web.dto.CallChainTreeNode; +import com.ai.cloud.skywalking.web.dto.TypicalCallTree; import com.ai.cloud.skywalking.web.service.inter.IAnalysisResultService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -12,10 +14,7 @@ import org.springframework.stereotype.Service; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; +import java.util.*; /** * Created by xin on 16-4-25. @@ -28,6 +27,9 @@ public class AnalysisResultService implements IAnalysisResultService { @Autowired private ICallChainTreeDao callChainTreeDao; + @Autowired + private ITypicalCallTreeDao typicalCallTreeDao; + @Override public CallChainTree fetchAnalysisResult(String treeId, String analyType, String analyDate) throws ParseException, IOException { String tableName = null; @@ -79,4 +81,26 @@ public class AnalysisResultService implements IAnalysisResultService { return callChainTree; } + + @Override + public List fetchTypicalCallTrees(String treeId, String analyDate) throws ParseException, IOException { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); + Date date = format.parse(analyDate); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + + String rowKey = treeId + "@" + calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH); + //load treeID + String[] typicalCallTreeIds = typicalCallTreeDao.queryAllCombineCallChainTreeIds(rowKey); + if (typicalCallTreeIds == null) { + return new ArrayList(); + } + List typicalCallTrees = new ArrayList(); + for (String callTreeId : typicalCallTreeIds) { + TypicalCallTree typicalCallTree = typicalCallTreeDao.queryCallChainTree(callTreeId); + typicalCallTrees.add(typicalCallTree); + } + + return typicalCallTrees; + } } diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/service/inter/IAnalysisResultService.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/service/inter/IAnalysisResultService.java index f29b090dc244911618da250bcac1455e9d5a5bed..faaa2fd351bb66eec3c3ffa6ed4303aab31275cc 100644 --- a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/service/inter/IAnalysisResultService.java +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/service/inter/IAnalysisResultService.java @@ -1,13 +1,17 @@ package com.ai.cloud.skywalking.web.service.inter; import com.ai.cloud.skywalking.web.dto.CallChainTree; +import com.ai.cloud.skywalking.web.dto.TypicalCallTree; import java.io.IOException; import java.text.ParseException; +import java.util.List; /** * Created by xin on 16-4-25. */ public interface IAnalysisResultService { CallChainTree fetchAnalysisResult(String treeId, String analyType, String analyDate) throws ParseException, IOException; + + List fetchTypicalCallTrees(String treeId, String analyDate) throws ParseException, IOException; } diff --git a/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/util/TokenGenerator.java b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/util/TokenGenerator.java new file mode 100644 index 0000000000000000000000000000000000000000..fa40057951fd3ecc17b3006d874f9cd8cde92ea9 --- /dev/null +++ b/skywalking-webui/src/main/java/com/ai/cloud/skywalking/web/util/TokenGenerator.java @@ -0,0 +1,34 @@ +package com.ai.cloud.skywalking.web.util; + + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public final class TokenGenerator { + + private static Logger logger = LogManager.getLogger(TokenGenerator.class); + + public static String generate(String originData) { + StringBuilder result = new StringBuilder(); + if (originData != null) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte bytes[] = md.digest(originData.getBytes()); + for (int i = 0; i < bytes.length; i++) { + String str = Integer.toHexString(bytes[i] & 0xFF); + if (str.length() == 1) { + str += "F"; + } + result.append(str); + } + } catch (NoSuchAlgorithmException e) { + logger.error("Cannot found algorithm.", e); + System.exit(-1); + } + } + return result.toString().toUpperCase(); + } +} diff --git a/skywalking-webui/src/main/webapp/bower_components/skywalking/js/analysisResult.js b/skywalking-webui/src/main/webapp/bower_components/skywalking/js/analysisResult.js new file mode 100644 index 0000000000000000000000000000000000000000..5bbe4164655ef3e7359b354e10b4dd2198901511 --- /dev/null +++ b/skywalking-webui/src/main/webapp/bower_components/skywalking/js/analysisResult.js @@ -0,0 +1,219 @@ +function initAnalysisResult() { + + + $('#analyDate').datetimepicker({ + format: 'yyyy-mm-dd', + startView: 2, + minView: 2, + autoclose: true + }); + + $("#previousHourBtn").click(function () { + var analyType = "HOUR"; + var analyDate = getPreviousHour(); + paintAnalysisResult($("#treeId").val(), analyType, analyDate) + }); + + $("#yesterdayBtn").click(function () { + var analyType = "DAY"; + var analyDate = getYesterday(); + paintAnalysisResult($("#treeId").val(), analyType, analyDate) + }); + + $("#currentMonthBtn").click(function () { + var analyType = "MONTH"; + var analyDate = getCurrentMonth(); + paintAnalysisResult($("#treeId").val(), analyType, analyDate) + }); + + $("#previousMonthBtn").click(function () { + var analyType = "MONTH"; + var analyDate = getPreviousMonth(); + paintAnalysisResult($("#treeId").val(), analyType, analyDate) + }); + + + $("a[name='analyTypeDropDownOption']").each(function () { + $(this).click(function () { + $('#analyDate').val(""); + $("#analyTypeDropDown").text($(this).text()); + var value = $(this).attr("value"); + var modelView = 2; + var formatStr = 'yyyy-mm-dd'; + if (value == "HOUR") { + formatStr = 'yyyy-mm-dd:hh'; + modelView = 1; + } else if (value == "DAY") { + formatStr = 'yyyy-mm-dd'; + modelView = 2; + } else if (value == "MONTH") { + formatStr = 'yyyy-mm'; + modelView = 3; + } else { + formatStr = 'yyyy-mm-dd'; + modelView = 2; + } + $('#analyDate').datetimepicker('remove'); + $('#analyDate').datetimepicker({ + format: formatStr, + startView: modelView, + minView: modelView, + autoclose: true + }); + + $("#analyType").val(value); + }); + }); + + $("a[name='analyTypeDropDownOption'][value='MONTH']").click(); + $("#analyDate").val(getCurrentMonth()); + + $("#showAnalyResultBtn").click(function () { + paintAnalysisResult($("#treeId").val(), $("#analyType").val(), $("#analyDate").val()) + }); + + $("#showAnalyResultBtn").click(); +} + +function paintAnalysisResult(treeId, analyType, analyDate) { + var baseUrl = $("#baseUrl").text(); + var analysisResultUrl = baseUrl + "/analy/load/" + treeId + "/" + + analyType + "/" + analyDate; + $.ajax({ + type: 'POST', + url: analysisResultUrl, + dataType: 'json', + async: true, + success: function (data) { + if (data.code == '200') { + var dataResult = convertAnalysisResult(jQuery.parseJSON(data.result)); + var template = $.templates("#analysisResultTableTmpl"); + var htmlOutput = template.render(dataResult); + $("#dataBody").empty(); + $("#dataBody").html(htmlOutput); + } + }, + error: function () { + $("#errorMessage").text("Fatal Error, please try it again."); + $("#alertMessageBox").show(); + } + }); + var typicalCallUrl = baseUrl + "/analy/load/" + treeId + "/" + analyDate; + + $.ajax({ + type: 'POST', + url: typicalCallUrl, + dataType: 'json', + async: true, + success: function (data) { + if (data.code == '200') { + //data.result + } + }, + error: function () { + $("#errorMessage").text("Fatal Error, please try it again."); + $("#alertMessageBox").show(); + } + }); +} + +function convertAnalysisResult(originData) { + if (originData == undefined || originData.callChainTreeNodeList == undefined) { + return []; + } + var previousNodeLevelId = ""; + var index = -1; + var count = 1; + var flag = false; + for (var i = 0; i < originData.callChainTreeNodeList.length; i++) { + var node = originData.callChainTreeNodeList[i]; + + if (previousNodeLevelId == node.traceLevelId) { + if (count == 1) { + index = i - 1; + } + count++; + flag = true; + } + + if (flag){ + originData.callChainTreeNodeList[i].isPrintLevelId = false; + originData.callChainTreeNodeList[index].rowSpanCount = count; + flag = false; + }else{ + count = 1; + originData.callChainTreeNodeList[i].rowSpanCount = count; + originData.callChainTreeNodeList[i].isPrintLevelId = true; + } + + if (node.anlyResult.totalCall > 0) { + node.anlyResult.correctRate = + (parseFloat(node.anlyResult.correctNumber) + / parseFloat(node.anlyResult.totalCall) * 100).toFixed(2); + + node.anlyResult.averageCost = + (parseFloat(node.anlyResult.totalCostTime) + / parseFloat(node.anlyResult.totalCall)).toFixed(2); + } else { + node.anlyResult.correctRate = (0).toFixed(2); + node.anlyResult.averageCost = (0).toFixed(2); + } + previousNodeLevelId = node.traceLevelId; + } + + return originData.callChainTreeNodeList; +} + +function getPreviousHour() { + var date = new Date(); + var seperator1 = "-"; + var seperator2 = ":"; + var month = date.getMonth() + 1; + var strDate = date.getDate(); + if (month >= 1 && month <= 9) { + month = "0" + month; + } + if (strDate >= 0 && strDate <= 9) { + strDate = "0" + strDate; + } + return date.getFullYear() + seperator1 + month + seperator1 + strDate + seperator2 + (date.getHours() - 1); +} + +function getYesterday() { + var date = new Date(); + var seperator1 = "-"; + var month = date.getMonth() + 1; + var strDate = date.getDate() - 1; + if (month >= 1 && month <= 9) { + month = "0" + month; + } + if (strDate >= 0 && strDate <= 9) { + strDate = "0" + strDate; + } + return date.getFullYear() + seperator1 + month + seperator1 + strDate; +} + +function getCurrentMonth() { + var date = new Date(); + var seperator1 = "-"; + var month = date.getMonth() + 1; + if (month >= 1 && month <= 9) { + month = "0" + month; + } + return date.getFullYear() + seperator1 + month; +} + +function getPreviousMonth() { + var date = new Date(); + var seperator1 = "-"; + var month = date.getMonth(); + var year = date.getFullYear(); + if (month == 0) { + year = date.getFullYear() - 1; + month = 12; + } + if (month >= 1 && month <= 9) { + month = "0" + month; + } + return year + seperator1 + month; +} \ No newline at end of file diff --git a/skywalking-webui/src/main/webapp/bower_components/skywalking/js/analysisresult.js b/skywalking-webui/src/main/webapp/bower_components/skywalking/js/analysisSearchResult.js similarity index 100% rename from skywalking-webui/src/main/webapp/bower_components/skywalking/js/analysisresult.js rename to skywalking-webui/src/main/webapp/bower_components/skywalking/js/analysisSearchResult.js diff --git a/skywalking-webui/src/main/webapp/pages/anls-result/analysisResult.ftl b/skywalking-webui/src/main/webapp/pages/anls-result/analysisResult.ftl index c14a33b90ca03255baa9bb8380bf0cd6d85e3489..00e2164d9aa3400c4bf88921c7785d7a40c0ddfa 100644 --- a/skywalking-webui/src/main/webapp/pages/anls-result/analysisResult.ftl +++ b/skywalking-webui/src/main/webapp/pages/anls-result/analysisResult.ftl @@ -1,20 +1,5 @@ -<#import "../common/commons.ftl" as common> - - - - - - -<@common.importResources /> - - - - - - -<@common.navbar/> -
+<#macro analysisResult> + + + +<#macro analysisResultTableTmpl> + - -
- - \ No newline at end of file + + \ No newline at end of file diff --git a/skywalking-webui/src/main/webapp/pages/anls-result/analysisSearchResult.ftl b/skywalking-webui/src/main/webapp/pages/anls-result/analysisSearchResult.ftl index fa9cfbb31f8dcb40d9b6d9d7c16f30bbe9bb3e0a..92e4be9f5ef02ef9d3b0f7d61a4cea4884dabac1 100644 --- a/skywalking-webui/src/main/webapp/pages/anls-result/analysisSearchResult.ftl +++ b/skywalking-webui/src/main/webapp/pages/anls-result/analysisSearchResult.ftl @@ -13,7 +13,7 @@ <#macro anlyResultDisplayTmpl> - + + + + - + <@common.navbar/> <@traceInfo.traceTableTmpl/> @@ -34,9 +38,11 @@ <@applicationMaintain.createglobalConfig/> <@applicationMaintain.modifyApplication/> <@auth.downloadAuth/> -<@anlyResult.anlyResultTmpl/> -<@anlyResult.anlyResultDisplayTmpl/> -<@anlyResult.pageInfoTmpl/> +<@anlySearchResult.anlyResultTmpl/> +<@anlySearchResult.anlyResultDisplayTmpl/> +<@anlySearchResult.pageInfoTmpl/> +<@anlyResult.analysisResult/> +<@anlyResult.analysisResultTableTmpl/>
@@ -51,22 +57,24 @@ // bind $("#searchBtn").click(function () { var searchKey = $("#searchKey").val(); - if (searchKey.match(/viewpoint:*/i)){ - loadContent("showAnlyResult") - }else { + if (searchKey.match(/viewpoint:*/i)) { + loadContent("showAnlySearchResult") + } else if (searchKey.match(/analyResult:*/i)){ + loadContent("showAnalysisResult"); + } else{ loadContent("showTraceInfo"); } }) }); - function loadContent(loadType,applicationId){ + function loadContent(loadType, param) { - if (loadType == "showTraceInfo"){ + if (loadType == "showTraceInfo") { loadTraceTreeData("${_base}"); return; } - if (loadType == "showAnlyResult"){ + if (loadType == "showAnlySearchResult") { var template = $.templates("#anlyResultPanelTmpl"); var htmlOutput = template.render({}); $("#mainPanel").empty(); @@ -80,12 +88,27 @@ return; } + if (loadType == "showAnalysisResult") { + var searchKey = $("#searchKey").val(); + var index = searchKey.indexOf(':'); + if (index != -1) { + searchKey = searchKey.substr(index + 1); + } + + var template = $.templates("#analysisResultPanelTmpl"); + var htmlOutput = template.render({treeId: searchKey}); + $("#mainPanel").empty(); + $("#mainPanel").html(htmlOutput); + initAnalysisResult() + return; + } + if (loadType == "applicationList") { loadAllApplications(); return; } - if (loadType == "addApplication"){ + if (loadType == "addApplication") { var template = $.templates("#addApplicationTmpl"); var htmlOutput = template.render({}); $("#mainPanel").empty(); @@ -94,7 +117,7 @@ return; } - if (loadType == "createGlobalApplication"){ + if (loadType == "createGlobalApplication") { var template = $.templates("#createGlobalConfigTmpl"); var htmlOutput = template.render({}); $("#mainPanel").empty(); @@ -103,24 +126,25 @@ return; } - if (loadType == "modifyApplication"){ + if (loadType == "modifyApplication") { var template = $.templates("#modifyApplicationTmpl"); - var htmlOutput = template.render({applicationId:applicationId}); + var htmlOutput = template.render({applicationId: param}); $("#mainPanel").empty(); $("#mainPanel").html(htmlOutput); modifyApplication(); return; } - if (loadType == "downloadAuthFile"){ + if (loadType == "downloadAuthFile") { var template = $.templates("#downloadAuthFileTmpl"); - var htmlOutput = template.render({applicationCode:applicationId}); + var htmlOutput = template.render({applicationCode: param}); $("#mainPanel").empty(); $("#mainPanel").html(htmlOutput); toDownloadAuthFile(); return; } + $("#mainPanel").empty(); } diff --git a/skywalking-webui/src/test/java/test/json/TestJSON.java b/skywalking-webui/src/test/java/test/json/TestJSON.java new file mode 100644 index 0000000000000000000000000000000000000000..90d286c8213bfbba7fb4a48f401e0a27d3c2b33e --- /dev/null +++ b/skywalking-webui/src/test/java/test/json/TestJSON.java @@ -0,0 +1,47 @@ +package test.json; + +import com.ai.cloud.skywalking.web.dto.AnlyResult; +import com.ai.cloud.skywalking.web.entity.BreviaryChainTree; +import com.ai.cloud.skywalking.web.util.Constants; +import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by xin on 16-4-18. + */ +public class TestJSON { + + public static void main(String[] args) { + List chainTreeList = new ArrayList(); + BreviaryChainTree chainTree = new BreviaryChainTree("Test"); + chainTree.setEntranceViewpoint("testPoint"); + AnlyResult anlyResult = new AnlyResult(); + anlyResult.setCorrectNumber(10); + anlyResult.setHumanInterruptionNumber(0); + anlyResult.setTotalCall(20); + anlyResult.setTotalCostTime(1000); + chainTree.setEntranceAnlyResult(anlyResult); + chainTreeList.add(chainTree); + JSONObject jsonObject = new JSONObject(); + + JsonObject result = new JsonObject(); + if (chainTreeList.size() > Constants.MAX_ANALYSIS_RESULT_PAGE_SIZE) { + result.addProperty("hasNextPage", true); + chainTreeList.remove(chainTreeList.size() - 1); + } else { + result.addProperty("hasNexPage", false); + } + JsonElement jsonElements = new JsonParser().parse(new Gson().toJson(chainTreeList)); + result.add("children", jsonElements); + jsonObject.put("code", "200"); + jsonObject.put("result", result.toString()); + + System.out.println(jsonObject.toString()); + } +}