* 演示获取Hystrix的Metrics.
*/
public MetricsMap getHystrixMetrics() {
MetricsMap metricsMap = new MetricsMap();
HystrixCommandKey key = HystrixCommandKey.Factory.asKey("GetUserCommand");
HystrixCommandMetrics metrics = HystrixCommandMetrics.getInstance(key);
if (metrics != null) {
HealthCounts counts = metrics.getHealthCounts();
HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);
metricsMap.put("circuitOpen", circuitBreaker.isOpen());
metricsMap.put("totalRequest", counts.getTotalRequests());
metricsMap.put("errorPercentage", counts.getErrorPercentage());
metricsMap.put("success", metrics.getRollingCount(HystrixRollingNumberEvent.SUCCESS));
metricsMap.put("timeout", metrics.getRollingCount(HystrixRollingNumberEvent.TIMEOUT));
metricsMap.put("failure", metrics.getRollingCount(HystrixRollingNumberEvent.FAILURE));
metricsMap.put("shortCircuited", metrics.getRollingCount(HystrixRollingNumberEvent.SHORT_CIRCUITED));
metricsMap.put("threadPoolRejected",
metrics.getRollingCount(HystrixRollingNumberEvent.THREAD_POOL_REJECTED));
metricsMap.put("semaphoreRejected", metrics.getRollingCount(HystrixRollingNumberEvent.SEMAPHORE_REJECTED));
metricsMap.put("latency50", metrics.getTotalTimePercentile(50));
metricsMap.put("latency90", metrics.getTotalTimePercentile(90));
metricsMap.put("latency100", metrics.getTotalTimePercentile(100));
}
return metricsMap;
}