|
@@ -5,6 +5,7 @@ import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
|
|
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
|
@@ -12,6 +13,7 @@ import org.springframework.boot.actuate.endpoint.annotation.Selector;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
|
+import com.codahale.metrics.ConsoleReporter;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
@@ -43,6 +45,10 @@ public class ApiStatusEndpoint {
|
|
|
return get("");
|
|
|
}
|
|
|
|
|
|
+ private static ConsoleReporter consoleReporter = ConsoleReporter
|
|
|
+ .forRegistry(MetricRegistryHolder.getDefalut()).convertRatesTo(TimeUnit.SECONDS)
|
|
|
+ .convertDurationsTo(TimeUnit.MILLISECONDS).build();
|
|
|
+
|
|
|
/**
|
|
|
* url: /actuator/api-status/ignored?order=XX
|
|
|
*
|
|
@@ -55,69 +61,78 @@ public class ApiStatusEndpoint {
|
|
|
|
|
|
System.out.println("order by " + order);
|
|
|
ReportorHolder.getApiDataReportor().report();
|
|
|
+ consoleReporter.report();
|
|
|
List<ReportInfo> reportInfoList = ReportorHolder.getApiDataReportor().getReportInfoList();
|
|
|
|
|
|
ReportInfo reportInfo = reportInfoList.get(0);
|
|
|
+ List<HistogramInfo> histogramInfoList = reportInfo.getHistogramInfoList();
|
|
|
List<MeterInfo> meterInfoList = reportInfo.getMeterInfoList();
|
|
|
- List<TimerInfo> timerInfoList = reportInfo.getTimerInfoList();
|
|
|
-
|
|
|
- Map<String, MeterInfo> meterInfoMap = Maps.newHashMap();
|
|
|
|
|
|
+ Map<String, MeterInfo> apiErrMeterInfoMap = Maps.newHashMap();
|
|
|
for (MeterInfo meterInfo : meterInfoList) {
|
|
|
String key = meterInfo.getKey();
|
|
|
- if (!key.startsWith(MetricNames.API_ERROR_METER.name())) {
|
|
|
- continue;
|
|
|
+ if (key.startsWith(MetricNames.API_ERROR_METER.name())) {
|
|
|
+ String mapping = key.substring(MetricNames.API_ERROR_METER.name().length() + 1);
|
|
|
+ apiErrMeterInfoMap.put(mapping, meterInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
}
|
|
|
- String mapping = key.substring(MetricNames.API_ERROR_METER.name().length() + 1);
|
|
|
- meterInfoMap.put(mapping, meterInfo);
|
|
|
}
|
|
|
|
|
|
List<ApiStatusInfo> list = Lists.newArrayList();
|
|
|
|
|
|
- for (TimerInfo timerInfo : timerInfoList) {
|
|
|
- String key = timerInfo.getKey();
|
|
|
- if (!key.startsWith(MetricNames.API_TIMER.name())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ for (MeterInfo cur : meterInfoList) {
|
|
|
+ String key = cur.getKey();
|
|
|
+ if (key.startsWith(MetricNames.API_METER.name())) {
|
|
|
|
|
|
- String mapping = key.substring(MetricNames.API_TIMER.name().length() + 1);
|
|
|
+ String mapping = key.substring(MetricNames.API_METER.name().length() + 1);
|
|
|
|
|
|
- ApiStatusInfo apiStatusInfo = new ApiStatusInfo();
|
|
|
- list.add(apiStatusInfo);
|
|
|
+ ApiStatusInfo apiStatusInfo = new ApiStatusInfo();
|
|
|
+ list.add(apiStatusInfo);
|
|
|
|
|
|
- apiStatusInfo.setMapping(mapping);
|
|
|
+ apiStatusInfo.setMapping(mapping);
|
|
|
|
|
|
- ApiInfo apiInfo = ApiInfoHolder.getApiInfo(mapping);
|
|
|
- if (null != apiInfo) {
|
|
|
- apiStatusInfo.setDescription(apiInfo.getDescription());
|
|
|
- }
|
|
|
+ ApiInfo apiInfo = ApiInfoHolder.getApiInfo(mapping);
|
|
|
+ if (null != apiInfo) {
|
|
|
+ apiStatusInfo.setDescription(apiInfo.getDescription());
|
|
|
+ }
|
|
|
|
|
|
- apiStatusInfo.setCount(timerInfo.getCount());
|
|
|
- apiStatusInfo.setMeanRate(timerInfo.getMeanRate());
|
|
|
- apiStatusInfo.setOneMinuteRate(timerInfo.getOneMinuteRate());
|
|
|
- apiStatusInfo.setFiveMinuteRate(timerInfo.getFiveMinuteRate());
|
|
|
- apiStatusInfo.setFifteenMinuteRate(timerInfo.getFifteenMinuteRate());
|
|
|
-
|
|
|
- apiStatusInfo.setMin(timerInfo.getMin());
|
|
|
- apiStatusInfo.setMax(timerInfo.getMax());
|
|
|
- apiStatusInfo.setMean(timerInfo.getMean());
|
|
|
-
|
|
|
- apiStatusInfo.setP50(timerInfo.getP50());
|
|
|
- apiStatusInfo.setP75(timerInfo.getP75());
|
|
|
- apiStatusInfo.setP95(timerInfo.getP95());
|
|
|
- apiStatusInfo.setP98(timerInfo.getP98());
|
|
|
- apiStatusInfo.setP99(timerInfo.getP99());
|
|
|
-
|
|
|
- MeterInfo meterInfo = meterInfoMap.get(mapping);
|
|
|
- if (null == meterInfo) {
|
|
|
- apiStatusInfo.setErrorCount(0L);
|
|
|
- apiStatusInfo.setErrorPercent(0D);
|
|
|
- } else {
|
|
|
- apiStatusInfo.setErrorCount(meterInfo.getCount());
|
|
|
- apiStatusInfo.setErrorPercent(
|
|
|
- getPercent(meterInfo.getMeanRate(), timerInfo.getMeanRate()));
|
|
|
- }
|
|
|
+ apiStatusInfo.setCount(cur.getCount());
|
|
|
+ apiStatusInfo.setMeanRate(cur.getMeanRate());
|
|
|
+ apiStatusInfo.setOneMinuteRate(cur.getOneMinuteRate());
|
|
|
+ apiStatusInfo.setFiveMinuteRate(cur.getFiveMinuteRate());
|
|
|
+ apiStatusInfo.setFifteenMinuteRate(cur.getFifteenMinuteRate());
|
|
|
+
|
|
|
+ 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());
|
|
|
+
|
|
|
+ MeterInfo apiErrMeterInfo = apiErrMeterInfoMap.get(mapping);
|
|
|
+ if (null == apiErrMeterInfo) {
|
|
|
+ apiStatusInfo.setErrorCount(0L);
|
|
|
+ apiStatusInfo.setErrorPercent(0D);
|
|
|
+ } else {
|
|
|
+ apiStatusInfo.setErrorCount(apiErrMeterInfo.getCount());
|
|
|
+ apiStatusInfo.setErrorPercent(
|
|
|
+ getPercent(apiErrMeterInfo.getMeanRate(), cur.getMeanRate()));
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Collections.sort(list, new Comparator<ApiStatusInfo>() {
|