...
|
...
|
@@ -31,42 +31,42 @@ public class ApiStatisticsResultStore { |
|
|
logger.info("store api statistics result to hbase ");
|
|
|
|
|
|
//调试打印
|
|
|
if (logger.isDebugEnabled()) {
|
|
|
apiResultRdd.foreach(
|
|
|
new VoidFunction<Tuple2<String, ApiTraceResult>>() {
|
|
|
@Override
|
|
|
public void call(Tuple2<String, ApiTraceResult> tuple2) throws Exception {
|
|
|
|
|
|
ApiTraceResult result = tuple2._2();
|
|
|
|
|
|
logger.debug("++++++++++++++++++++++++++++++++++++++++++++");
|
|
|
logger.debug(" ");
|
|
|
logger.debug("API:" + result.getApiName());
|
|
|
logger.debug(" Avg Response(ms): " + result.getDuration() + " ms");
|
|
|
logger.debug(" Times: " + result.getCallTimes());
|
|
|
logger.debug(" max latency: " + result.getMaxLatencyTrace() + " " + result.getMaxLatency() + " ms");
|
|
|
logger.debug(" min latency: " + result.getMinLatencyTrace() + " " + result.getMinLatency() + " ms");
|
|
|
logger.debug(" Sample Trace: ");
|
|
|
|
|
|
List<SpanResult> list = result.getSpans();
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
for (int n = 0; n < list.get(i).getLevel(); n++) {
|
|
|
sb.append(" ");
|
|
|
}
|
|
|
logger.debug(" " + i + ":" + sb.toString() + list.get(i).getSpanName()
|
|
|
+ " (" + String.valueOf(list.get(i).getDuration()) + "ms) "
|
|
|
+ " id:" + list.get(i).getSpanId()
|
|
|
+ " parent:" + list.get(i).getParent());
|
|
|
}
|
|
|
|
|
|
Thread.sleep(200);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
// if (logger.isDebugEnabled()) {
|
|
|
// apiResultRdd.foreach(
|
|
|
// new VoidFunction<Tuple2<String, ApiTraceResult>>() {
|
|
|
// @Override
|
|
|
// public void call(Tuple2<String, ApiTraceResult> tuple2) throws Exception {
|
|
|
//
|
|
|
// ApiTraceResult result = tuple2._2();
|
|
|
//
|
|
|
// logger.debug("++++++++++++++++++++++++++++++++++++++++++++");
|
|
|
// logger.debug(" ");
|
|
|
// logger.debug("API:" + result.getApiName());
|
|
|
// logger.debug(" Avg Response(ms): " + result.getDuration() + " ms");
|
|
|
// logger.debug(" Times: " + result.getCallTimes());
|
|
|
// logger.debug(" max latency: " + result.getMaxLatencyTrace() + " " + result.getMaxLatency() + " ms");
|
|
|
// logger.debug(" min latency: " + result.getMinLatencyTrace() + " " + result.getMinLatency() + " ms");
|
|
|
// logger.debug(" Sample Trace: ");
|
|
|
//
|
|
|
// List<SpanResult> list = result.getSpans();
|
|
|
// for (int i = 0; i < list.size(); i++) {
|
|
|
//
|
|
|
// StringBuffer sb = new StringBuffer();
|
|
|
// for (int n = 0; n < list.get(i).getLevel(); n++) {
|
|
|
// sb.append(" ");
|
|
|
// }
|
|
|
// logger.debug(" " + i + ":" + sb.toString() + list.get(i).getSpanName()
|
|
|
// + " (" + String.valueOf(list.get(i).getDuration()) + "ms) "
|
|
|
// + " id:" + list.get(i).getSpanId()
|
|
|
// + " parent:" + list.get(i).getParent());
|
|
|
// }
|
|
|
//
|
|
|
// Thread.sleep(200);
|
|
|
//
|
|
|
// }
|
|
|
// }
|
|
|
// );
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -84,18 +84,21 @@ public class ApiStatisticsResultStore { |
|
|
}
|
|
|
|
|
|
List<Put> putList = new ArrayList<>();
|
|
|
long now = System.currentTimeMillis()/1000;
|
|
|
while(tuple2Iterator.hasNext()){
|
|
|
Tuple2<String, ApiTraceResult> next = tuple2Iterator.next();
|
|
|
ApiTraceResult apiTraceResult = next._2;
|
|
|
String rowkey = apiTraceResult.getApiName() + ":" + apiTraceResult.getTraceMd5();
|
|
|
Put put = new Put(Bytes.toBytes(rowkey));
|
|
|
put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("api"), Bytes.toBytes(apiTraceResult.getApiName()));
|
|
|
String[] md5Tags = StringUtils.split(apiTraceResult.getTraceMd5(), '.');
|
|
|
if (null == md5Tags || 2 != md5Tags.length) {
|
|
|
put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("traceMd5"), Bytes.toBytes(StringUtils.EMPTY));
|
|
|
} else {
|
|
|
put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("traceMd5"), Bytes.toBytes(md5Tags[1]));
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
String md5 = md5Tags[1];
|
|
|
|
|
|
String rowkey = apiTraceResult.getApiName() + ":" + now + ":" + md5;
|
|
|
Put put = new Put(Bytes.toBytes(rowkey));
|
|
|
put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("api"), Bytes.toBytes(apiTraceResult.getApiName()));
|
|
|
|
|
|
put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("duration"), Bytes.toBytes(apiTraceResult.getDuration()));
|
|
|
put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("times"), Bytes.toBytes(apiTraceResult.getCallTimes()));
|
|
|
put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("maxLatency"), Bytes.toBytes(apiTraceResult.getMaxLatency()));
|
...
|
...
|
|