1. 完成二次MapReduce功能
This commit is contained in:
parent
921ea2723d
commit
622bfacb36
|
|
@ -49,7 +49,7 @@ public class Categorize2ChainMapper extends TableMapper<Text, ChainInfo> {
|
|||
|
||||
chainInfo = spanToChainInfo(Bytes.toString(key.get()), spanList);
|
||||
logger.info("Success convert span to chain info...."
|
||||
+ chainInfo.getCID());
|
||||
+ chainInfo.getCID() + " TraceId : " + Bytes.toString(key.get()));
|
||||
context.write(
|
||||
new Text(chainInfo.getUserId() + ":"
|
||||
+ chainInfo.getEntranceNodeToken()), chainInfo);
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ public class Categorize2ChainReducer extends Reducer<Text, ChainInfo, Text, IntW
|
|||
public static int reduceAction(String key, Iterator<ChainInfo> chainInfoIterator) throws IOException, InterruptedException {
|
||||
int totalCount = 0;
|
||||
try {
|
||||
ChainRelationship chainRelate = HBaseUtil.selectCallChainRelationship(key.toString());
|
||||
ChainSummary summary = new ChainSummary();
|
||||
ChainRelationship chainRelate = HBaseUtil.loadCallChainRelationship(key.toString());
|
||||
ChainSummaryWithoutRelationship summary = new ChainSummaryWithoutRelationship();
|
||||
while (chainInfoIterator.hasNext()) {
|
||||
ChainInfo chainInfo = chainInfoIterator.next();
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import com.google.gson.JsonObject;
|
|||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
|
@ -18,7 +20,7 @@ public class CategorizedChainInfo {
|
|||
private List<String> children_Token;
|
||||
|
||||
public CategorizedChainInfo(ChainInfo chainInfo) {
|
||||
cid = chainInfo.getCID();
|
||||
cid = chainInfo.getCID();
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
boolean flag = false;
|
||||
|
|
@ -26,7 +28,7 @@ public class CategorizedChainInfo {
|
|||
if (flag) {
|
||||
stringBuilder.append(";");
|
||||
}
|
||||
stringBuilder.append(chainNode.getNodeToken());
|
||||
stringBuilder.append(chainNode.getTraceLevelId() + "-" + chainNode.getNodeToken());
|
||||
flag = true;
|
||||
}
|
||||
|
||||
|
|
@ -52,6 +54,10 @@ public class CategorizedChainInfo {
|
|||
return pattern.matcher(this.chainFullToken).find();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(1453507835957L)));
|
||||
}
|
||||
|
||||
public boolean isAlreadyContained(UncategorizeChainInfo uncategorizeChainInfo) {
|
||||
return children_Token.contains(uncategorizeChainInfo.getCID());
|
||||
}
|
||||
|
|
@ -64,4 +70,8 @@ public class CategorizedChainInfo {
|
|||
public String toString() {
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
|
||||
public List<String> getChildren_Token() {
|
||||
return children_Token;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,14 @@ public class ChainNodeSpecificTimeWindowSummary {
|
|||
public static final long INTERVAL = 1L;
|
||||
|
||||
private String traceLevelId;
|
||||
|
||||
private String nodeToken;
|
||||
// key : 分钟
|
||||
private Map<String, ChainNodeSpecificTimeWindowSummaryValue> summerValueMap;
|
||||
|
||||
public static ChainNodeSpecificTimeWindowSummary newInstance(String traceLevelId) {
|
||||
public static ChainNodeSpecificTimeWindowSummary newInstance(String traceLevelId, String nodeToken) {
|
||||
ChainNodeSpecificTimeWindowSummary cns = new ChainNodeSpecificTimeWindowSummary();
|
||||
cns.traceLevelId = traceLevelId;
|
||||
cns.nodeToken = nodeToken;
|
||||
return cns;
|
||||
}
|
||||
|
||||
|
|
@ -32,6 +34,7 @@ public class ChainNodeSpecificTimeWindowSummary {
|
|||
summerValueMap = new Gson().fromJson(jsonObject.get("summerValueMap").toString(),
|
||||
new TypeToken<Map<String, ChainNodeSpecificTimeWindowSummaryValue>>() {
|
||||
}.getType());
|
||||
nodeToken = jsonObject.get("nodeToken").getAsString();
|
||||
}
|
||||
|
||||
public String getTraceLevelId() {
|
||||
|
|
@ -57,4 +60,12 @@ public class ChainNodeSpecificTimeWindowSummary {
|
|||
public String toString() {
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
|
||||
public String getNodeToken() {
|
||||
return nodeToken;
|
||||
}
|
||||
|
||||
public Map<String, ChainNodeSpecificTimeWindowSummaryValue> getSummerValueMap() {
|
||||
return summerValueMap;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,18 +19,10 @@ public class ChainNodeSpecificTimeWindowSummaryValue {
|
|||
return totalCall;
|
||||
}
|
||||
|
||||
public void setTotalCall(long totalCall) {
|
||||
this.totalCall = totalCall;
|
||||
}
|
||||
|
||||
public long getTotalCostTime() {
|
||||
return totalCostTime;
|
||||
}
|
||||
|
||||
public void setTotalCostTime(long totalCostTime) {
|
||||
this.totalCostTime = totalCostTime;
|
||||
}
|
||||
|
||||
public long getCorrectNumber() {
|
||||
return correctNumber;
|
||||
}
|
||||
|
|
@ -39,10 +31,6 @@ public class ChainNodeSpecificTimeWindowSummaryValue {
|
|||
return humanInterruptionNumber;
|
||||
}
|
||||
|
||||
public void setCorrectNumber(long correctNumber) {
|
||||
this.correctNumber = correctNumber;
|
||||
}
|
||||
|
||||
public void summary(ChainNode node) {
|
||||
totalCall++;
|
||||
if (node.getStatus() == ChainNode.NodeStatus.NORMAL) {
|
||||
|
|
@ -53,4 +41,11 @@ public class ChainNodeSpecificTimeWindowSummaryValue {
|
|||
}
|
||||
totalCostTime += node.getCost();
|
||||
}
|
||||
|
||||
public void accumulate(ChainNodeSpecificTimeWindowSummaryValue value) {
|
||||
this.totalCall += value.getTotalCall();
|
||||
this.correctNumber += value.getCorrectNumber();
|
||||
this.totalCostTime += value.getTotalCostTime();
|
||||
this.humanInterruptionNumber += value.getHumanInterruptionNumber();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ public class ChainRelationship {
|
|||
if (entry.getValue().isAlreadyContained(child)) {
|
||||
isContained = true;
|
||||
} else if (entry.getValue().isContained(child)) {
|
||||
logger.info("There has contained :" + entry.getKey() + " " + child.getCID());
|
||||
entry.getValue().add(child);
|
||||
chainDetailMap.put(child.getCID(), new ChainDetail(child.getChainInfo(), false));
|
||||
isContained = true;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class ChainSpecificTimeWindowSummary {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(ChainSpecificTimeWindowSummary.class.getName());
|
||||
/**
|
||||
* key : cid + 时间窗口
|
||||
* key : cid + uid + 时间窗口
|
||||
*/
|
||||
private Map<String, ChainNodeSpecificTimeWindowSummary> chainNodeSummaryResultMap;
|
||||
|
||||
|
|
@ -23,12 +23,12 @@ public class ChainSpecificTimeWindowSummary {
|
|||
chainNodeSummaryResultMap = new HashMap<String, ChainNodeSpecificTimeWindowSummary>();
|
||||
}
|
||||
|
||||
public static ChainSpecificTimeWindowSummary load(String cid_time) {
|
||||
public static ChainSpecificTimeWindowSummary load(String cid_uid_time) {
|
||||
ChainSpecificTimeWindowSummary result = null;
|
||||
try {
|
||||
result = HBaseUtil.selectChainSummaryResult(cid_time);
|
||||
result = HBaseUtil.selectChainSummaryResult(cid_uid_time);
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to load the key[" + cid_time + "] summary result.", e);
|
||||
logger.error("Failed to load the key[" + cid_uid_time + "] summary result.", e);
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
|
|
@ -45,7 +45,7 @@ public class ChainSpecificTimeWindowSummary {
|
|||
String tlid = node.getTraceLevelId();
|
||||
ChainNodeSpecificTimeWindowSummary chainNodeSummaryResult = chainNodeSummaryResultMap.get(tlid);
|
||||
if (chainNodeSummaryResult == null) {
|
||||
chainNodeSummaryResult = ChainNodeSpecificTimeWindowSummary.newInstance(tlid);
|
||||
chainNodeSummaryResult = ChainNodeSpecificTimeWindowSummary.newInstance(tlid, node.getNodeToken());
|
||||
chainNodeSummaryResultMap.put(tlid, chainNodeSummaryResult);
|
||||
}
|
||||
chainNodeSummaryResult.summary(node);
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ import java.sql.Timestamp;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class ChainSummary {
|
||||
public class ChainSummaryWithoutRelationship {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ChainSummary.class.getName());
|
||||
private static Logger logger = LoggerFactory.getLogger(ChainSummaryWithoutRelationship.class.getName());
|
||||
private Map<String, ChainSpecificTimeWindowSummary> loadedChainSpecificTimeWindowSummary;
|
||||
private Map<String, Timestamp> updateChainInfo;
|
||||
|
||||
public ChainSummary() {
|
||||
public ChainSummaryWithoutRelationship() {
|
||||
loadedChainSpecificTimeWindowSummary = new HashMap<String, ChainSpecificTimeWindowSummary>();
|
||||
updateChainInfo = new HashMap<String, Timestamp>();
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ public class DBCallChainInfoDao {
|
|||
connection = DriverManager.getConnection(Config.MySql.URL,
|
||||
Config.MySql.USERNAME, Config.MySql.PASSWORD);
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.error("Failed to find jdbc driver class["
|
||||
logger.error("Failed to searchRelationship jdbc driver class["
|
||||
+ Config.MySql.DRIVER_CLASS + "]", e);
|
||||
System.exit(-1);
|
||||
} catch (SQLException e) {
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public class SpanEntry {
|
|||
|
||||
if (serverSpan != null) {
|
||||
if (serverSpan.getExceptionStack() != null && serverSpan.getExceptionStack().length() > 0) {
|
||||
if(clientSpan.getStatusCode() == 1){
|
||||
if(clientSpan != null && clientSpan.getStatusCode() == 1){
|
||||
return ChainNode.NodeStatus.ABNORMAL;
|
||||
}else{
|
||||
return ChainNode.NodeStatus.HUMAN_INTERRUPTION;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class SpanNodeProcessChain {
|
|||
try {
|
||||
properties.load(SpanNodeProcessChain.class.getResourceAsStream("/viewpointfilter.conf"));
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to find config file[viewpointfilter.conf]", e);
|
||||
logger.error("Failed to searchRelationship config file[viewpointfilter.conf]", e);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ public class SpanNodeProcessChain {
|
|||
tmpSpanNodeFilter.setNextProcessChain(currentFilter);
|
||||
currentFilter = tmpSpanNodeFilter;
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.error("Filed to find class[" + Config.Filter.FILTER_PACKAGE_NAME + "." + filters[i] + "]", e);
|
||||
logger.error("Filed to searchRelationship class[" + Config.Filter.FILTER_PACKAGE_NAME + "." + filters[i] + "]", e);
|
||||
System.exit(-1);
|
||||
} catch (InstantiationException e) {
|
||||
logger.error("Can not instance class[" + Config.Filter.FILTER_PACKAGE_NAME + "." + filters[i] + "]", e);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.ai.cloud.skywalking.analysis.categorize2chain.util;
|
|||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.*;
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.model.ChainInfo;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.ChainRelationship4Search;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.model.*;
|
||||
import com.ai.cloud.skywalking.analysis.config.Config;
|
||||
import com.ai.cloud.skywalking.analysis.config.HBaseTableMetaData;
|
||||
import com.google.gson.Gson;
|
||||
|
|
@ -14,7 +16,9 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HBaseUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(HBaseUtil.class.getName());
|
||||
|
|
@ -26,13 +30,29 @@ public class HBaseUtil {
|
|||
try {
|
||||
initHBaseClient();
|
||||
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CID_TID_MAPPING.TABLE_NAME, HBaseTableMetaData.TABLE_CID_TID_MAPPING.COLUMN_FAMILY_NAME);
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CID_TID_MAPPING.TABLE_NAME,
|
||||
HBaseTableMetaData.TABLE_CID_TID_MAPPING.COLUMN_FAMILY_NAME);
|
||||
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CALL_CHAIN_RELATIONSHIP.TABLE_NAME, HBaseTableMetaData.TABLE_CALL_CHAIN_RELATIONSHIP.COLUMN_FAMILY_NAME);
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CALL_CHAIN_RELATIONSHIP.TABLE_NAME,
|
||||
HBaseTableMetaData.TABLE_CALL_CHAIN_RELATIONSHIP.COLUMN_FAMILY_NAME);
|
||||
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_EXCLUDE_RELATIONSHIP.TABLE_NAME, HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_EXCLUDE_RELATIONSHIP.COLUMN_FAMILY_NAME);
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_EXCLUDE_RELATIONSHIP.TABLE_NAME,
|
||||
HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_EXCLUDE_RELATIONSHIP.COLUMN_FAMILY_NAME);
|
||||
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CHAIN_DETAIL.TABLE_NAME, HBaseTableMetaData.TABLE_CHAIN_DETAIL.COLUMN_FAMILY_NAME);
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CHAIN_DETAIL.TABLE_NAME,
|
||||
HBaseTableMetaData.TABLE_CHAIN_DETAIL.COLUMN_FAMILY_NAME);
|
||||
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CHAIN_ONE_HOUR_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME,
|
||||
HBaseTableMetaData.TABLE_CHAIN_ONE_HOUR_SUMMARY_INCLUDE_RELATIONSHIP.COLUMN_FAMILY_NAME);
|
||||
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CHAIN_ONE_DAY_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME,
|
||||
HBaseTableMetaData.TABLE_CHAIN_ONE_DAY_SUMMARY_INCLUDE_RELATIONSHIP.COLUMN_FAMILY_NAME);
|
||||
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME,
|
||||
HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_INCLUDE_RELATIONSHIP.COLUMN_FAMILY_NAME);
|
||||
|
||||
createTableIfNeed(HBaseTableMetaData.TABLE_CHAIN_ONE_MONTH_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME,
|
||||
HBaseTableMetaData.TABLE_CHAIN_ONE_MONTH_SUMMARY_INCLUDE_RELATIONSHIP.COLUMN_FAMILY_NAME);
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error("Create tables failed", e);
|
||||
|
|
@ -61,7 +81,7 @@ public class HBaseUtil {
|
|||
connection = ConnectionFactory.createConnection(configuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean saveCidTidMapping(String traceId, ChainInfo chainInfo) {
|
||||
Table table = null;
|
||||
|
||||
|
|
@ -90,7 +110,7 @@ public class HBaseUtil {
|
|||
}
|
||||
|
||||
|
||||
public static ChainRelationship selectCallChainRelationship(String key) throws IOException {
|
||||
public static ChainRelationship loadCallChainRelationship(String key) throws IOException {
|
||||
ChainRelationship chainRelate = new ChainRelationship(key);
|
||||
Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CALL_CHAIN_RELATIONSHIP.TABLE_NAME));
|
||||
Get g = new Get(Bytes.toBytes(key));
|
||||
|
|
@ -167,4 +187,169 @@ public class HBaseUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ChainRelationship4Search queryChainRelationship(String key) throws IOException {
|
||||
Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_EXCLUDE_RELATIONSHIP.TABLE_NAME));
|
||||
Get g = new Get(key.getBytes());
|
||||
Result r = table.get(g);
|
||||
|
||||
if (r.rawCells().length == 0) {
|
||||
return null;
|
||||
}
|
||||
ChainRelationship4Search result = new ChainRelationship4Search();
|
||||
|
||||
for (Cell cell : r.rawCells()) {
|
||||
if (cell.getValueArray().length > 0) {
|
||||
String qualifierName = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(),
|
||||
cell.getQualifierLength());
|
||||
|
||||
if (HBaseTableMetaData.TABLE_CALL_CHAIN_RELATIONSHIP.UNCATEGORIZE_COLUMN_NAME.equals(qualifierName)) {
|
||||
List<UncategorizeChainInfo> uncategorizeChainInfoList = new Gson().fromJson(Bytes.toString(cell.getValueArray(),
|
||||
cell.getValueOffset(), cell.getValueLength()),
|
||||
new TypeToken<List<UncategorizeChainInfo>>() {
|
||||
}.getType());
|
||||
for (UncategorizeChainInfo chainInfo : uncategorizeChainInfoList) {
|
||||
result.addRelationship(chainInfo.getCID());
|
||||
}
|
||||
} else {
|
||||
CategorizedChainInfo categorizedChainInfo = new CategorizedChainInfo(
|
||||
Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())
|
||||
);
|
||||
|
||||
for (String cid : categorizedChainInfo.getChildren_Token()) {
|
||||
result.addRelationship(qualifierName, cid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ChainSpecificMinSummary loadSpecificMinSummary(String key) throws IOException {
|
||||
ChainSpecificMinSummary result = null;
|
||||
Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME));
|
||||
Get g = new Get(Bytes.toBytes(key));
|
||||
Result r = table.get(g);
|
||||
|
||||
if (r.rawCells().length == 0) {
|
||||
return null;
|
||||
}
|
||||
result = new ChainSpecificMinSummary();
|
||||
for (Cell cell : r.rawCells()) {
|
||||
if (cell.getValueArray().length > 0)
|
||||
result.addNodeSummaryResult(new ChainNodeSpecificMinSummary(Bytes.toString(cell.getValueArray(),
|
||||
cell.getValueOffset(), cell.getValueLength())));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ChainSpecificHourSummary loadSpecificHourSummary(String key) throws IOException {
|
||||
ChainSpecificHourSummary result = null;
|
||||
Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CHAIN_ONE_HOUR_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME));
|
||||
Get g = new Get(Bytes.toBytes(key));
|
||||
Result r = table.get(g);
|
||||
|
||||
if (r.rawCells().length == 0) {
|
||||
return null;
|
||||
}
|
||||
result = new ChainSpecificHourSummary();
|
||||
for (Cell cell : r.rawCells()) {
|
||||
if (cell.getValueArray().length > 0)
|
||||
result.addNodeSummaryResult(new ChainNodeSpecificHourSummary(Bytes.toString(cell.getValueArray(),
|
||||
cell.getValueOffset(), cell.getValueLength())));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ChainSpecificDaySummary loadSpecificDaySummary(String key) throws IOException {
|
||||
ChainSpecificDaySummary result = null;
|
||||
Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CHAIN_ONE_DAY_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME));
|
||||
Get g = new Get(Bytes.toBytes(key));
|
||||
Result r = table.get(g);
|
||||
|
||||
if (r.rawCells().length == 0) {
|
||||
return null;
|
||||
}
|
||||
result = new ChainSpecificDaySummary();
|
||||
for (Cell cell : r.rawCells()) {
|
||||
if (cell.getValueArray().length > 0)
|
||||
result.addNodeSummaryResult(new ChainNodeSpecificDaySummary(Bytes.toString(cell.getValueArray(),
|
||||
cell.getValueOffset(), cell.getValueLength())));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ChainSpecificMonthSummary loadSpecificMonthSummary(String key) throws IOException {
|
||||
ChainSpecificMonthSummary result = null;
|
||||
Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CHAIN_ONE_MONTH_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME));
|
||||
Get g = new Get(Bytes.toBytes(key));
|
||||
Result r = table.get(g);
|
||||
|
||||
if (r.rawCells().length == 0) {
|
||||
return null;
|
||||
}
|
||||
result = new ChainSpecificMonthSummary();
|
||||
for (Cell cell : r.rawCells()) {
|
||||
if (cell.getValueArray().length > 0)
|
||||
result.addNodeSummaryResult(new ChainNodeSpecificMonthSummary(Bytes.toString(cell.getValueArray(),
|
||||
cell.getValueOffset(), cell.getValueLength())));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void batchSaveSpecificMinSummary(Map<String, ChainSpecificMinSummary> minSummary) throws IOException, InterruptedException {
|
||||
List<Put> puts = new ArrayList<Put>();
|
||||
for (Map.Entry<String, ChainSpecificMinSummary> entry : minSummary.entrySet()) {
|
||||
Put put = new Put(entry.getKey().getBytes());
|
||||
entry.getValue().save(put);
|
||||
puts.add(put);
|
||||
}
|
||||
|
||||
batchSavePuts(puts, HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME);
|
||||
}
|
||||
|
||||
public static void batchSaveSpecificDaySummary(Map<String, ChainSpecificDaySummary> daySummaryMap) throws IOException, InterruptedException {
|
||||
List<Put> puts = new ArrayList<Put>();
|
||||
for (Map.Entry<String, ChainSpecificDaySummary> entry : daySummaryMap.entrySet()) {
|
||||
Put put = new Put(entry.getKey().getBytes());
|
||||
entry.getValue().save(put);
|
||||
puts.add(put);
|
||||
}
|
||||
|
||||
batchSavePuts(puts, HBaseTableMetaData.TABLE_CHAIN_ONE_DAY_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME);
|
||||
}
|
||||
|
||||
public static void batchSaveSpecificHourSummary(Map<String, ChainSpecificHourSummary> hourSummaryMap) throws IOException, InterruptedException {
|
||||
List<Put> puts = new ArrayList<Put>();
|
||||
for (Map.Entry<String, ChainSpecificHourSummary> entry : hourSummaryMap.entrySet()) {
|
||||
Put put = new Put(entry.getKey().getBytes());
|
||||
entry.getValue().save(put);
|
||||
puts.add(put);
|
||||
}
|
||||
|
||||
batchSavePuts(puts, HBaseTableMetaData.TABLE_CHAIN_ONE_HOUR_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME);
|
||||
}
|
||||
|
||||
public static void batchSaveSpecificMonthSummary(Map<String, ChainSpecificMonthSummary> monthSummaryMap) throws IOException, InterruptedException {
|
||||
List<Put> puts = new ArrayList<Put>();
|
||||
for (Map.Entry<String, ChainSpecificMonthSummary> entry : monthSummaryMap.entrySet()) {
|
||||
Put put = new Put(entry.getKey().getBytes());
|
||||
entry.getValue().save(put);
|
||||
puts.add(put);
|
||||
}
|
||||
|
||||
batchSavePuts(puts, HBaseTableMetaData.TABLE_CHAIN_ONE_MONTH_SUMMARY_INCLUDE_RELATIONSHIP.TABLE_NAME);
|
||||
}
|
||||
|
||||
private static void batchSavePuts(List<Put> puts, String tableName) throws IOException, InterruptedException {
|
||||
Object[] resultArrays = new Object[puts.size()];
|
||||
Table table = connection.getTable(TableName.valueOf(tableName));
|
||||
table.batch(puts, resultArrays);
|
||||
for (Object result : resultArrays) {
|
||||
if (result == null) {
|
||||
logger.error("Failed to save chain specific Summary");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.config.ConfigInitializer;
|
||||
import org.apache.hadoop.hbase.Cell;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
|
||||
import org.apache.hadoop.hbase.mapreduce.TableMapper;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Chain2SummaryMapper extends TableMapper<Text, Object> {
|
||||
|
||||
private Logger logger = LoggerFactory
|
||||
.getLogger(Chain2SummaryMapper.class.getName());
|
||||
|
||||
|
||||
@Override
|
||||
protected void setup(Context context) throws IOException,
|
||||
InterruptedException {
|
||||
ConfigInitializer.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException {
|
||||
try {
|
||||
ChainSpecificTimeSummary summary = new ChainSpecificTimeSummary(Bytes.toString(key.get()));
|
||||
for (Cell cell : value.rawCells()) {
|
||||
summary.addChainNodeSummaryResult(Bytes.toString(cell.getValueArray(),
|
||||
cell.getValueOffset(), cell.getValueLength()));
|
||||
}
|
||||
context.write(new Text(summary.buildMapperKey()), summary);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to mapper call chain[" + key.toString() + "]",
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.config.ConfigInitializer;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.io.IntWritable;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.apache.hadoop.mapreduce.Reducer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class Chain2SummaryReducer extends Reducer<Text, ChainSpecificTimeSummary, Text, IntWritable> {
|
||||
|
||||
@Override
|
||||
protected void setup(Context context) throws IOException, InterruptedException {
|
||||
ConfigInitializer.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reduce(Text key, Iterable<ChainSpecificTimeSummary> values, Context context) throws IOException, InterruptedException {
|
||||
ChainRelationship4Search chainRelationship = ChainRelationship4Search.load(Bytes.toString(key.getBytes()));
|
||||
Iterator<ChainSpecificTimeSummary> summaryIterator = values.iterator();
|
||||
Summary summary = new Summary();
|
||||
while (summaryIterator.hasNext()) {
|
||||
ChainSpecificTimeSummary timeSummary = summaryIterator.next();
|
||||
summary.summary(timeSummary, chainRelationship);
|
||||
}
|
||||
|
||||
summary.saveToHBase();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.util.HBaseUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainRelationship4Search {
|
||||
|
||||
// key: 正常链路ID value: 正常链路ID
|
||||
// key: 异常链路ID value: 正常链路ID
|
||||
// key: 未分类链路ID value: 未分类链路ID
|
||||
private Map<String, String> chainRelationshipMap = new HashMap<String, String>();
|
||||
|
||||
public static ChainRelationship4Search load(String rowkey) throws IOException {
|
||||
ChainRelationship4Search chainRelationship4Search = HBaseUtil.queryChainRelationship(rowkey);
|
||||
return chainRelationship4Search;
|
||||
}
|
||||
|
||||
public void addRelationship(String cid) {
|
||||
chainRelationshipMap.put(cid, cid);
|
||||
}
|
||||
|
||||
public void addRelationship(String normalCID, String abnormalCID) {
|
||||
chainRelationshipMap.put(normalCID, abnormalCID);
|
||||
}
|
||||
|
||||
public String searchRelationship(String cid) {
|
||||
return chainRelationshipMap.get(cid);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummary;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.apache.hadoop.io.Writable;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainSpecificTimeSummary implements Writable {
|
||||
private String cId;
|
||||
private String userId;
|
||||
private String entranceNodeToken;
|
||||
//key : TraceLevelId
|
||||
private Map<String, ChainNodeSpecificTimeWindowSummary> summaryMap;
|
||||
private long summaryTimestamp;
|
||||
|
||||
public ChainSpecificTimeSummary(String rowKey) throws ParseException {
|
||||
String[] splitValue = rowKey.split("-");
|
||||
this.cId = splitValue[0];
|
||||
this.userId = splitValue[1];
|
||||
this.summaryTimestamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(splitValue[2]).getTime();
|
||||
summaryMap = new HashMap<String, ChainNodeSpecificTimeWindowSummary>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput out) throws IOException {
|
||||
out.write(new Gson().toJson(this).getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFields(DataInput in) throws IOException {
|
||||
JsonObject jsonObject = (JsonObject) new JsonParser().parse(in.readLine());
|
||||
cId = jsonObject.get("cId").getAsString();
|
||||
userId = jsonObject.get("userId").getAsString();
|
||||
entranceNodeToken = jsonObject.get("entranceNodeToken").getAsString();
|
||||
summaryMap = new Gson().fromJson(jsonObject.get("summaryMap").toString(),
|
||||
new TypeToken<Map<String, ChainNodeSpecificTimeWindowSummary>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public void addChainNodeSummaryResult(String summaryResult) {
|
||||
ChainNodeSpecificTimeWindowSummary chainNodeSpecificTimeWindowSummary = new Gson().
|
||||
fromJson(summaryResult, ChainNodeSpecificTimeWindowSummary.class);
|
||||
|
||||
if ("0".equals(chainNodeSpecificTimeWindowSummary.getTraceLevelId())) {
|
||||
this.entranceNodeToken = chainNodeSpecificTimeWindowSummary.getNodeToken();
|
||||
}
|
||||
|
||||
summaryMap.put(chainNodeSpecificTimeWindowSummary.getTraceLevelId(), chainNodeSpecificTimeWindowSummary);
|
||||
}
|
||||
|
||||
public String buildMapperKey() {
|
||||
return userId + ":" + entranceNodeToken;
|
||||
}
|
||||
|
||||
|
||||
public String getcId() {
|
||||
return cId;
|
||||
}
|
||||
|
||||
public String getHourKey() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date(summaryTimestamp));
|
||||
return calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + calendar.get(Calendar.DAY_OF_MONTH)
|
||||
+ " " + calendar.get(Calendar.HOUR);
|
||||
}
|
||||
|
||||
public String getDayKey() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date(summaryTimestamp));
|
||||
return calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + calendar.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
public String getMonthKey() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date(summaryTimestamp));
|
||||
return calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH);
|
||||
}
|
||||
|
||||
public String getYearKey() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date(summaryTimestamp));
|
||||
return String.valueOf(calendar.get(Calendar.YEAR));
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public Map<String, ChainNodeSpecificTimeWindowSummary> getSummaryMap() {
|
||||
return summaryMap;
|
||||
}
|
||||
|
||||
public long getSummaryTimestamp() {
|
||||
return summaryTimestamp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.util.HBaseUtil;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.model.ChainSpecificDaySummary;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.model.ChainSpecificHourSummary;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.model.ChainSpecificMinSummary;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.model.ChainSpecificMonthSummary;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainSummaryWithRelationship {
|
||||
|
||||
private String cid;
|
||||
// key : cid + userId + 小时
|
||||
private Map<String, ChainSpecificMinSummary> minSummary;
|
||||
// key : cid + userId + 天
|
||||
private Map<String, ChainSpecificHourSummary> hourSummary;
|
||||
// key : cid + userId + 月
|
||||
private Map<String, ChainSpecificDaySummary> daySummary;
|
||||
// key : cid + userId + 年
|
||||
private Map<String, ChainSpecificMonthSummary> monthSummary;
|
||||
|
||||
public ChainSummaryWithRelationship(String cid) {
|
||||
this.cid = cid;
|
||||
minSummary = new HashMap<String, ChainSpecificMinSummary>();
|
||||
hourSummary = new HashMap<String, ChainSpecificHourSummary>();
|
||||
daySummary = new HashMap<String, ChainSpecificDaySummary>();
|
||||
monthSummary = new HashMap<String, ChainSpecificMonthSummary>();
|
||||
}
|
||||
|
||||
public void saveToHBase() throws IOException, InterruptedException {
|
||||
HBaseUtil.batchSaveSpecificMinSummary(minSummary);
|
||||
HBaseUtil.batchSaveSpecificHourSummary(hourSummary);
|
||||
HBaseUtil.batchSaveSpecificDaySummary(daySummary);
|
||||
HBaseUtil.batchSaveSpecificMonthSummary(monthSummary);
|
||||
}
|
||||
|
||||
public void summary(ChainSpecificTimeSummary timeSummary) throws IOException {
|
||||
loadSummaryIfNecessary(cid,timeSummary);
|
||||
//
|
||||
minSummary.get(buildMinSummaryRowKey(cid, timeSummary)).summary(timeSummary);
|
||||
hourSummary.get(buildHourSummaryRowKey(cid, timeSummary)).summary(timeSummary);
|
||||
daySummary.get(buildDaySummaryRowKey(cid, timeSummary)).summary(timeSummary);
|
||||
monthSummary.get(buildMonthSummaryRowKey(cid, timeSummary)).summary(timeSummary);
|
||||
}
|
||||
|
||||
|
||||
private void loadSummaryIfNecessary(String cid, ChainSpecificTimeSummary timeSummary) throws IOException {
|
||||
loadMinSummaryIfNecessary(cid, timeSummary);
|
||||
loadHourSummaryIfNecessary(cid, timeSummary);
|
||||
loadDaySummaryIfNecessary(cid, timeSummary);
|
||||
loadMonthSummaryIfNecessary(cid, timeSummary);
|
||||
}
|
||||
|
||||
private void loadMonthSummaryIfNecessary(String cid, ChainSpecificTimeSummary timeSummary) throws IOException {
|
||||
String month_RowKey = buildMonthSummaryRowKey(cid, timeSummary);
|
||||
if (!monthSummary.containsKey(month_RowKey)) {
|
||||
monthSummary.put(month_RowKey, HBaseUtil.loadSpecificMonthSummary(month_RowKey));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDaySummaryIfNecessary(String cid, ChainSpecificTimeSummary timeSummary) throws IOException {
|
||||
String day_RowKey = buildDaySummaryRowKey(cid, timeSummary);
|
||||
if (!daySummary.containsKey(day_RowKey)) {
|
||||
daySummary.put(day_RowKey, HBaseUtil.loadSpecificDaySummary(day_RowKey));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadHourSummaryIfNecessary(String cid, ChainSpecificTimeSummary timeSummary) throws IOException {
|
||||
String hour_RowKey = buildHourSummaryRowKey(cid, timeSummary);
|
||||
if (!hourSummary.containsKey(hour_RowKey)) {
|
||||
hourSummary.put(hour_RowKey, HBaseUtil.loadSpecificHourSummary(hour_RowKey));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadMinSummaryIfNecessary(String cid, ChainSpecificTimeSummary timeSummary) throws IOException {
|
||||
String min_RowKey = buildMinSummaryRowKey(cid, timeSummary);
|
||||
if (!minSummary.containsKey(min_RowKey)) {
|
||||
minSummary.put(min_RowKey, HBaseUtil.loadSpecificMinSummary(min_RowKey));
|
||||
}
|
||||
}
|
||||
|
||||
// 月统计是以年作为RowKey的
|
||||
private static String buildMonthSummaryRowKey(String cid, ChainSpecificTimeSummary timeSummary) {
|
||||
return cid + "-" + timeSummary.getUserId() + "-" + timeSummary.getYearKey();
|
||||
}
|
||||
|
||||
// 天统计是以月作为RowKey的
|
||||
private static String buildDaySummaryRowKey(String cid, ChainSpecificTimeSummary timeSummary) {
|
||||
return cid + "-" + timeSummary.getUserId() + "-" + timeSummary.getMonthKey();
|
||||
}
|
||||
|
||||
// 小时统计是以天作为RowKey的
|
||||
private static String buildHourSummaryRowKey(String cid, ChainSpecificTimeSummary timeSummary) {
|
||||
return cid + "-" + timeSummary.getUserId() + "-" + timeSummary.getDayKey();
|
||||
}
|
||||
|
||||
// 分钟统计是以小时作为RowKey的
|
||||
private static String buildMinSummaryRowKey(String cid, ChainSpecificTimeSummary timeSummary) {
|
||||
return cid + "-" + timeSummary.getUserId() + "-" + timeSummary.getHourKey();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class Summary {
|
||||
private Map<String, ChainSummaryWithRelationship> stringChainSummaryWithRelationshipMap;
|
||||
|
||||
public void summary(ChainSpecificTimeSummary timeSummary, ChainRelationship4Search chainRelationship) throws IOException {
|
||||
String cid = chainRelationship.searchRelationship(timeSummary.getcId());
|
||||
if (cid == null || cid.length() == 0) {
|
||||
cid = timeSummary.getcId();
|
||||
}
|
||||
|
||||
if (!stringChainSummaryWithRelationshipMap.containsKey(cid)) {
|
||||
stringChainSummaryWithRelationshipMap.put(cid, new ChainSummaryWithRelationship(cid));
|
||||
}
|
||||
|
||||
ChainSummaryWithRelationship chainSummaryWithRelationship = stringChainSummaryWithRelationshipMap.get(cid);
|
||||
chainSummaryWithRelationship.summary(timeSummary);
|
||||
}
|
||||
|
||||
public void saveToHBase() throws IOException, InterruptedException {
|
||||
for (Map.Entry<String, ChainSummaryWithRelationship> entry : stringChainSummaryWithRelationshipMap.entrySet()) {
|
||||
entry.getValue().saveToHBase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary.model;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummary;
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummaryValue;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainNodeSpecificDaySummary {
|
||||
private String traceLevelId;
|
||||
// key: 天
|
||||
private Map<String, ChainNodeSpecificTimeWindowSummaryValue> summerValueMap;
|
||||
|
||||
public ChainNodeSpecificDaySummary(String originData) {
|
||||
JsonObject jsonObject = (JsonObject) new JsonParser().parse(originData);
|
||||
traceLevelId = jsonObject.get("traceLevelId").getAsString();
|
||||
summerValueMap = new Gson().fromJson(jsonObject.get("summerValueMap").toString(),
|
||||
new TypeToken<Map<String, ChainNodeSpecificTimeWindowSummaryValue>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public String getTraceLevelId() {
|
||||
return traceLevelId;
|
||||
}
|
||||
|
||||
public void summary(long summaryTimestamp,ChainNodeSpecificTimeWindowSummary value) {
|
||||
for (Map.Entry<String, ChainNodeSpecificTimeWindowSummaryValue> entry : value.getSummerValueMap().entrySet()) {
|
||||
summerValueMap.get(generateSummaryValueMapKey(summaryTimestamp)).accumulate(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private String generateSummaryValueMapKey(long timeStamp) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date(timeStamp));
|
||||
return String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary.model;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummary;
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummaryValue;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainNodeSpecificHourSummary {
|
||||
private String traceLevelId;
|
||||
// key : 小时
|
||||
private Map<String, ChainNodeSpecificTimeWindowSummaryValue> summerValueMap;
|
||||
|
||||
public ChainNodeSpecificHourSummary(String originData) {
|
||||
JsonObject jsonObject = (JsonObject) new JsonParser().parse(originData);
|
||||
traceLevelId = jsonObject.get("traceLevelId").getAsString();
|
||||
summerValueMap = new Gson().fromJson(jsonObject.get("summerValueMap").toString(),
|
||||
new TypeToken<Map<String, ChainNodeSpecificTimeWindowSummaryValue>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public String getTraceLevelId() {
|
||||
return traceLevelId;
|
||||
}
|
||||
|
||||
public void summary(long summaryTimestamp, ChainNodeSpecificTimeWindowSummary value) {
|
||||
for (Map.Entry<String, ChainNodeSpecificTimeWindowSummaryValue> entry : value.getSummerValueMap().entrySet()) {
|
||||
summerValueMap.get(generateSummaryValueMapKey(summaryTimestamp)).accumulate(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private String generateSummaryValueMapKey(long timeStamp) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date(timeStamp));
|
||||
return String.valueOf(calendar.get(Calendar.HOUR));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary.model;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummary;
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummaryValue;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainNodeSpecificMinSummary {
|
||||
|
||||
private String traceLevelId;
|
||||
// key: 分钟 value: 统计结果
|
||||
private Map<String, ChainNodeSpecificTimeWindowSummaryValue> summerValueMap;
|
||||
|
||||
|
||||
public ChainNodeSpecificMinSummary(String originData) {
|
||||
JsonObject jsonObject = (JsonObject) new JsonParser().parse(originData);
|
||||
traceLevelId = jsonObject.get("traceLevelId").getAsString();
|
||||
summerValueMap = new Gson().fromJson(jsonObject.get("summerValueMap").toString(),
|
||||
new TypeToken<Map<String, ChainNodeSpecificTimeWindowSummaryValue>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public String getTraceLevelId() {
|
||||
return traceLevelId;
|
||||
}
|
||||
|
||||
public void summary(ChainNodeSpecificTimeWindowSummary value) {
|
||||
for (Map.Entry<String, ChainNodeSpecificTimeWindowSummaryValue> entry :value.getSummerValueMap().entrySet()){
|
||||
summerValueMap.get(entry.getKey()).accumulate(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary.model;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummary;
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummaryValue;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainNodeSpecificMonthSummary {
|
||||
|
||||
private Map<String, ChainNodeSpecificTimeWindowSummaryValue> summerValueMap;
|
||||
private String traceLevelId;
|
||||
|
||||
public ChainNodeSpecificMonthSummary(String originData) {
|
||||
JsonObject jsonObject = (JsonObject) new JsonParser().parse(originData);
|
||||
traceLevelId = jsonObject.get("traceLevelId").getAsString();
|
||||
summerValueMap = new Gson().fromJson(jsonObject.get("summerValueMap").toString(),
|
||||
new TypeToken<Map<String, ChainNodeSpecificTimeWindowSummaryValue>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public void summary(long summaryTimestamp, ChainNodeSpecificTimeWindowSummary value) {
|
||||
for (Map.Entry<String, ChainNodeSpecificTimeWindowSummaryValue> entry : value.getSummerValueMap().entrySet()) {
|
||||
summerValueMap.get(generateSummaryValueMapKey(summaryTimestamp)).accumulate(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public String getTraceLevelId() {
|
||||
return traceLevelId;
|
||||
}
|
||||
|
||||
private String generateSummaryValueMapKey(long timeStamp) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date(timeStamp));
|
||||
return String.valueOf(calendar.get(Calendar.MONTH));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary.model;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummary;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.ChainSpecificTimeSummary;
|
||||
import com.ai.cloud.skywalking.analysis.config.HBaseTableMetaData;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainSpecificDaySummary {
|
||||
private Map<String, ChainNodeSpecificDaySummary> chainNodeSpecificHourSummaryMap;
|
||||
|
||||
public ChainSpecificDaySummary() {
|
||||
chainNodeSpecificHourSummaryMap = new HashMap<String, ChainNodeSpecificDaySummary>();
|
||||
}
|
||||
|
||||
public void addNodeSummaryResult(ChainNodeSpecificDaySummary chainNodeSpecificHourSummary) {
|
||||
chainNodeSpecificHourSummaryMap.put(chainNodeSpecificHourSummary.getTraceLevelId(), chainNodeSpecificHourSummary);
|
||||
}
|
||||
|
||||
public void summary(ChainSpecificTimeSummary timeSummary) {
|
||||
Map<String, ChainNodeSpecificTimeWindowSummary> chainNodeSpecificTimeWindowSummaryMap = timeSummary.getSummaryMap();
|
||||
|
||||
for (Map.Entry<String, ChainNodeSpecificTimeWindowSummary> entry : chainNodeSpecificTimeWindowSummaryMap.entrySet()) {
|
||||
chainNodeSpecificHourSummaryMap.get(entry.getKey()).summary(timeSummary.getSummaryTimestamp(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void save(Put put) {
|
||||
for (Map.Entry<String, ChainNodeSpecificDaySummary> entry : chainNodeSpecificHourSummaryMap.entrySet()) {
|
||||
put.addColumn(HBaseTableMetaData.TABLE_CHAIN_ONE_DAY_SUMMARY_INCLUDE_RELATIONSHIP.
|
||||
COLUMN_FAMILY_NAME.getBytes(), entry.getKey().getBytes(),
|
||||
entry.getValue().toString().getBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary.model;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummary;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.ChainSpecificTimeSummary;
|
||||
import com.ai.cloud.skywalking.analysis.config.HBaseTableMetaData;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainSpecificHourSummary {
|
||||
// key : TraceLevelId
|
||||
private Map<String, ChainNodeSpecificHourSummary> chainNodeSpecificHourSummaryMap;
|
||||
|
||||
public ChainSpecificHourSummary() {
|
||||
chainNodeSpecificHourSummaryMap = new HashMap<String, ChainNodeSpecificHourSummary>();
|
||||
}
|
||||
|
||||
public void addNodeSummaryResult(ChainNodeSpecificHourSummary chainNodeSpecificHourSummary) {
|
||||
chainNodeSpecificHourSummaryMap.put(chainNodeSpecificHourSummary.getTraceLevelId(), chainNodeSpecificHourSummary);
|
||||
}
|
||||
|
||||
public void summary(ChainSpecificTimeSummary timeSummary) {
|
||||
Map<String, ChainNodeSpecificTimeWindowSummary> chainNodeSpecificTimeWindowSummaryMap = timeSummary.getSummaryMap();
|
||||
|
||||
for (Map.Entry<String, ChainNodeSpecificTimeWindowSummary> entry : chainNodeSpecificTimeWindowSummaryMap.entrySet()){
|
||||
chainNodeSpecificHourSummaryMap.get(entry.getKey()).summary(timeSummary.getSummaryTimestamp(),entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void save(Put put) {
|
||||
for (Map.Entry<String, ChainNodeSpecificHourSummary> entry : chainNodeSpecificHourSummaryMap.entrySet()) {
|
||||
put.addColumn(HBaseTableMetaData.TABLE_CHAIN_ONE_HOUR_SUMMARY_INCLUDE_RELATIONSHIP.
|
||||
COLUMN_FAMILY_NAME.getBytes(), entry.getKey().getBytes(),
|
||||
entry.getValue().toString().getBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary.model;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummary;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.ChainSpecificTimeSummary;
|
||||
import com.ai.cloud.skywalking.analysis.config.HBaseTableMetaData;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainSpecificMinSummary {
|
||||
|
||||
// Key: TraceLevelId
|
||||
private Map<String, ChainNodeSpecificMinSummary> chainNodeSpecificMinSummaryMap;
|
||||
|
||||
public ChainSpecificMinSummary() {
|
||||
this.chainNodeSpecificMinSummaryMap = new HashMap<String, ChainNodeSpecificMinSummary>();
|
||||
}
|
||||
|
||||
public void addNodeSummaryResult(ChainNodeSpecificMinSummary chainNodeSpecificMinSummary) {
|
||||
chainNodeSpecificMinSummaryMap.put(chainNodeSpecificMinSummary.getTraceLevelId(), chainNodeSpecificMinSummary);
|
||||
}
|
||||
|
||||
public void summary(ChainSpecificTimeSummary timeSummary) {
|
||||
Map<String, ChainNodeSpecificTimeWindowSummary> chainNodeSpecificTimeWindowSummaryMap = timeSummary.getSummaryMap();
|
||||
|
||||
for (Map.Entry<String, ChainNodeSpecificTimeWindowSummary> entry : chainNodeSpecificTimeWindowSummaryMap.entrySet()) {
|
||||
chainNodeSpecificMinSummaryMap.get(entry.getKey()).summary(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void save(Put put) {
|
||||
for (Map.Entry<String, ChainNodeSpecificMinSummary> entry : chainNodeSpecificMinSummaryMap.entrySet()) {
|
||||
put.addColumn(HBaseTableMetaData.TABLE_CHAIN_ONE_MINUTE_SUMMARY_INCLUDE_RELATIONSHIP.
|
||||
COLUMN_FAMILY_NAME.getBytes(), entry.getKey().getBytes(),
|
||||
entry.getValue().toString().getBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.ai.cloud.skywalking.analysis.chain2summary.model;
|
||||
|
||||
import com.ai.cloud.skywalking.analysis.categorize2chain.ChainNodeSpecificTimeWindowSummary;
|
||||
import com.ai.cloud.skywalking.analysis.chain2summary.ChainSpecificTimeSummary;
|
||||
import com.ai.cloud.skywalking.analysis.config.HBaseTableMetaData;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChainSpecificMonthSummary {
|
||||
|
||||
// Key: TraceLevelId
|
||||
private Map<String, ChainNodeSpecificMonthSummary> chainNodeSpecificMinSummaryMap;
|
||||
|
||||
public void addNodeSummaryResult(ChainNodeSpecificMonthSummary chainNodeSpecificDaySummary) {
|
||||
chainNodeSpecificMinSummaryMap.put(chainNodeSpecificDaySummary.getTraceLevelId(), chainNodeSpecificDaySummary);
|
||||
}
|
||||
|
||||
public void summary(ChainSpecificTimeSummary timeSummary) {
|
||||
Map<String, ChainNodeSpecificTimeWindowSummary> chainNodeSpecificTimeWindowSummaryMap = timeSummary.getSummaryMap();
|
||||
|
||||
for (Map.Entry<String, ChainNodeSpecificTimeWindowSummary> entry : chainNodeSpecificTimeWindowSummaryMap.entrySet()) {
|
||||
chainNodeSpecificMinSummaryMap.get(entry.getKey()).summary(timeSummary.getSummaryTimestamp(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void save(Put put) {
|
||||
for (Map.Entry<String, ChainNodeSpecificMonthSummary> entry : chainNodeSpecificMinSummaryMap.entrySet()) {
|
||||
put.addColumn(HBaseTableMetaData.TABLE_CHAIN_ONE_MONTH_SUMMARY_INCLUDE_RELATIONSHIP.
|
||||
COLUMN_FAMILY_NAME.getBytes(), entry.getKey().getBytes(),
|
||||
entry.getValue().toString().getBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +1,104 @@
|
|||
package com.ai.cloud.skywalking.analysis.config;
|
||||
|
||||
public class HBaseTableMetaData {
|
||||
/**
|
||||
* 调用链明细表,前端收集程序入库数据
|
||||
*
|
||||
* @author wusheng
|
||||
*
|
||||
*/
|
||||
public final static class TABLE_CALL_CHAIN {
|
||||
public static final String TABLE_NAME = "sw-call-chain";
|
||||
}
|
||||
/**
|
||||
* 调用链明细表,前端收集程序入库数据
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public final static class TABLE_CALL_CHAIN {
|
||||
public static final String TABLE_NAME = "sw-call-chain";
|
||||
}
|
||||
|
||||
/**
|
||||
* HBase 表:用于存放CID,TID的映射关系表
|
||||
*
|
||||
* @author wusheng
|
||||
*
|
||||
*/
|
||||
public final static class TABLE_CID_TID_MAPPING {
|
||||
public static final String TABLE_NAME = "sw-cid-tid-mapping";
|
||||
/**
|
||||
* HBase 表:用于存放CID,TID的映射关系表
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public final static class TABLE_CID_TID_MAPPING {
|
||||
public static final String TABLE_NAME = "sw-cid-tid-mapping";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "trace_info";
|
||||
|
||||
public static final String CID_COLUMN_NAME = "cid";
|
||||
}
|
||||
public static final String COLUMN_FAMILY_NAME = "trace_info";
|
||||
|
||||
/**
|
||||
* CID明细信息表
|
||||
*
|
||||
* @author wusheng
|
||||
*
|
||||
*/
|
||||
public final static class TABLE_CHAIN_DETAIL {
|
||||
public static final String TABLE_NAME = "sw-chain-detail";
|
||||
public static final String CID_COLUMN_NAME = "cid";
|
||||
}
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain_detail";
|
||||
}
|
||||
|
||||
/**
|
||||
* CID间关系表,记录异常CID和正常CID间的归属关系
|
||||
*
|
||||
* @author wusheng
|
||||
*
|
||||
*/
|
||||
public final static class TABLE_CALL_CHAIN_RELATIONSHIP {
|
||||
public static final String TABLE_NAME = "sw-chain-relationship";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain-relationship";
|
||||
|
||||
public static final String UNCATEGORIZE_COLUMN_NAME = "UNCATEGORIZED_CALL_CHAIN";
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于存放每个CID在一分钟内的汇总,汇总结果不包含关系汇总
|
||||
*
|
||||
* @author wusheng
|
||||
*
|
||||
*/
|
||||
public final static class TABLE_CHAIN_ONE_MINUTE_SUMMARY_EXCLUDE_RELATIONSHIP{
|
||||
public static final String TABLE_NAME = "sw-chain-1min-summary-ex-rela";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain_summary";
|
||||
}
|
||||
/**
|
||||
* CID明细信息表
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public final static class TABLE_CHAIN_DETAIL {
|
||||
public static final String TABLE_NAME = "sw-chain-detail";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain_detail";
|
||||
}
|
||||
|
||||
/**
|
||||
* CID间关系表,记录异常CID和正常CID间的归属关系
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public final static class TABLE_CALL_CHAIN_RELATIONSHIP {
|
||||
public static final String TABLE_NAME = "sw-chain-relationship";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain-relationship";
|
||||
|
||||
public static final String UNCATEGORIZE_COLUMN_NAME = "UNCATEGORIZED_CALL_CHAIN";
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于存放每个CID在一分钟内的汇总,汇总结果不包含关系汇总
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public final static class TABLE_CHAIN_ONE_MINUTE_SUMMARY_EXCLUDE_RELATIONSHIP {
|
||||
public static final String TABLE_NAME = "sw-chain-1min-summary-ex-rela";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain_summary";
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于存放每个CID在一分钟内的汇总,汇总结果不包含关系汇总
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public final static class TABLE_CHAIN_ONE_MINUTE_SUMMARY_INCLUDE_RELATIONSHIP {
|
||||
public static final String TABLE_NAME = "sw-chain-1min-summary-ic-rela";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain_summary";
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于存放每个CID在一小时内的汇总,汇总结果不包含关系汇总
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public final static class TABLE_CHAIN_ONE_HOUR_SUMMARY_INCLUDE_RELATIONSHIP {
|
||||
public static final String TABLE_NAME = "sw-chain-1hour-summary-ic-rela";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain_summary";
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于存放每个CID在一天内的汇总,汇总结果不包含关系汇总
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public final static class TABLE_CHAIN_ONE_DAY_SUMMARY_INCLUDE_RELATIONSHIP {
|
||||
public static final String TABLE_NAME = "sw-chain-1day-summary-ic-rela";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain_summary";
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于存放每个CID在一月内的汇总,汇总结果不包含关系汇总
|
||||
*
|
||||
* @author wusheng
|
||||
*/
|
||||
public final static class TABLE_CHAIN_ONE_MONTH_SUMMARY_INCLUDE_RELATIONSHIP {
|
||||
public static final String TABLE_NAME = "sw-chain-1mon-summary-ic-rela";
|
||||
|
||||
public static final String COLUMN_FAMILY_NAME = "chain_summary";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue