|
@@ -9,6 +9,7 @@ import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.util.Calculator;
|
|
import cn.com.qmth.examcloud.commons.util.Calculator;
|
|
|
|
+import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
import cn.com.qmth.examcloud.web.support.ApiInfo;
|
|
import cn.com.qmth.examcloud.web.support.ApiInfo;
|
|
import cn.com.qmth.examcloud.web.support.ApiInfoHolder;
|
|
import cn.com.qmth.examcloud.web.support.ApiInfoHolder;
|
|
|
|
|
|
@@ -17,8 +18,15 @@ public class ApiStatusInfoCollector {
|
|
|
|
|
|
public synchronized List<ApiStatusInfo> collect(ReportInfo reportInfo) {
|
|
public synchronized List<ApiStatusInfo> collect(ReportInfo reportInfo) {
|
|
|
|
|
|
|
|
+ // 耗时直方图算法:U:uniform ; B:biased
|
|
|
|
+ String algorithm = PropertyHolder.getString("$API.statistic.histograms.algorithm", "B");
|
|
|
|
+ if (!(algorithm.equals("B") || algorithm.equals("U"))) {
|
|
|
|
+ throw new RuntimeException("histograms algorithm must be 'U' or 'B'");
|
|
|
|
+ }
|
|
|
|
+
|
|
List<HistogramInfo> histogramInfoList = reportInfo.getHistogramInfoList();
|
|
List<HistogramInfo> histogramInfoList = reportInfo.getHistogramInfoList();
|
|
List<MeterInfo> meterInfoList = reportInfo.getMeterInfoList();
|
|
List<MeterInfo> meterInfoList = reportInfo.getMeterInfoList();
|
|
|
|
+ List<TimerInfo> timerInfoList = reportInfo.getTimerInfoList();
|
|
|
|
|
|
Map<String, MeterInfo> apiErrMeterInfoMap = Maps.newHashMap();
|
|
Map<String, MeterInfo> apiErrMeterInfoMap = Maps.newHashMap();
|
|
for (MeterInfo meterInfo : meterInfoList) {
|
|
for (MeterInfo meterInfo : meterInfoList) {
|
|
@@ -30,11 +38,24 @@ public class ApiStatusInfoCollector {
|
|
}
|
|
}
|
|
|
|
|
|
Map<String, HistogramInfo> apiHistogramInfoMap = Maps.newHashMap();
|
|
Map<String, HistogramInfo> apiHistogramInfoMap = Maps.newHashMap();
|
|
- for (HistogramInfo histogramInfo : histogramInfoList) {
|
|
|
|
- String key = histogramInfo.getKey();
|
|
|
|
- if (key.startsWith(MetricNames.API_HISTOGRAM.name())) {
|
|
|
|
- String mapping = key.substring(MetricNames.API_HISTOGRAM.name().length() + 1);
|
|
|
|
- apiHistogramInfoMap.put(mapping, histogramInfo);
|
|
|
|
|
|
+ if (algorithm.equals("U")) {
|
|
|
|
+ for (HistogramInfo histogramInfo : histogramInfoList) {
|
|
|
|
+ String key = histogramInfo.getKey();
|
|
|
|
+ if (key.startsWith(MetricNames.API_HISTOGRAM.name())) {
|
|
|
|
+ String mapping = key.substring(MetricNames.API_HISTOGRAM.name().length() + 1);
|
|
|
|
+ apiHistogramInfoMap.put(mapping, histogramInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, TimerInfo> apiTimerInfoMap = Maps.newHashMap();
|
|
|
|
+ if (algorithm.equals("B")) {
|
|
|
|
+ for (TimerInfo timerInfo : timerInfoList) {
|
|
|
|
+ String key = timerInfo.getKey();
|
|
|
|
+ if (key.startsWith(MetricNames.API_TIMER.name())) {
|
|
|
|
+ String mapping = key.substring(MetricNames.API_TIMER.name().length() + 1);
|
|
|
|
+ apiTimerInfoMap.put(mapping, timerInfo);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -62,17 +83,33 @@ public class ApiStatusInfoCollector {
|
|
apiStatusInfo.setFiveMinuteRate(cur.getFiveMinuteRate());
|
|
apiStatusInfo.setFiveMinuteRate(cur.getFiveMinuteRate());
|
|
apiStatusInfo.setFifteenMinuteRate(cur.getFifteenMinuteRate());
|
|
apiStatusInfo.setFifteenMinuteRate(cur.getFifteenMinuteRate());
|
|
|
|
|
|
- HistogramInfo histogramInfo = apiHistogramInfoMap.get(mapping);
|
|
|
|
|
|
+ if (algorithm.equals("U")) {
|
|
|
|
+ HistogramInfo histogramInfo = apiHistogramInfoMap.get(mapping);
|
|
|
|
+
|
|
|
|
+ apiStatusInfo.setMin(histogramInfo.getMin());
|
|
|
|
+ apiStatusInfo.setMax(histogramInfo.getMax());
|
|
|
|
+ apiStatusInfo.setMean(histogramInfo.getMean());
|
|
|
|
+
|
|
|
|
+ apiStatusInfo.setP50(histogramInfo.getP50());
|
|
|
|
+ apiStatusInfo.setP75(histogramInfo.getP75());
|
|
|
|
+ apiStatusInfo.setP95(histogramInfo.getP95());
|
|
|
|
+ apiStatusInfo.setP98(histogramInfo.getP98());
|
|
|
|
+ apiStatusInfo.setP99(histogramInfo.getP99());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (algorithm.equals("B")) {
|
|
|
|
+ TimerInfo timerInfo = apiTimerInfoMap.get(mapping);
|
|
|
|
|
|
- apiStatusInfo.setMin(histogramInfo.getMin());
|
|
|
|
- apiStatusInfo.setMax(histogramInfo.getMax());
|
|
|
|
- apiStatusInfo.setMean(histogramInfo.getMean());
|
|
|
|
|
|
+ apiStatusInfo.setMin(timerInfo.getMin());
|
|
|
|
+ apiStatusInfo.setMax(timerInfo.getMax());
|
|
|
|
+ apiStatusInfo.setMean(timerInfo.getMean());
|
|
|
|
|
|
- apiStatusInfo.setP50(histogramInfo.getP50());
|
|
|
|
- apiStatusInfo.setP75(histogramInfo.getP75());
|
|
|
|
- apiStatusInfo.setP95(histogramInfo.getP95());
|
|
|
|
- apiStatusInfo.setP98(histogramInfo.getP98());
|
|
|
|
- apiStatusInfo.setP99(histogramInfo.getP99());
|
|
|
|
|
|
+ apiStatusInfo.setP50(timerInfo.getP50());
|
|
|
|
+ apiStatusInfo.setP75(timerInfo.getP75());
|
|
|
|
+ apiStatusInfo.setP95(timerInfo.getP95());
|
|
|
|
+ apiStatusInfo.setP98(timerInfo.getP98());
|
|
|
|
+ apiStatusInfo.setP99(timerInfo.getP99());
|
|
|
|
+ }
|
|
|
|
|
|
MeterInfo apiErrMeterInfo = apiErrMeterInfoMap.get(mapping);
|
|
MeterInfo apiErrMeterInfo = apiErrMeterInfoMap.get(mapping);
|
|
if (null == apiErrMeterInfo) {
|
|
if (null == apiErrMeterInfo) {
|