本文整理汇总了Java中com.netflix.hystrix.metric.HystrixCommandCompletionStream类的典型用法代码示例。如果您正苦于以下问题:Java HystrixCommandCompletionStream类的具体用法?Java HystrixCommandCompletionStream怎么用?Java HystrixCommandCompletionStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HystrixCommandCompletionStream类属于com.netflix.hystrix.metric包,在下文中一共展示了HystrixCommandCompletionStream类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.netflix.hystrix.metric.HystrixCommandCompletionStream; //导入依赖的package包/类
@Override
public void initialize(HystrixCommandMetrics metrics) {
if (filter.test(metrics)) {
final HystrixCommandKey key = metrics.getCommandKey();
log.debug("Aggregate stream for command {}", key.name());
streams.onNext(HystrixCommandCompletionStream.getInstance(key).observe());
}
}
示例2: initialize
import com.netflix.hystrix.metric.HystrixCommandCompletionStream; //导入依赖的package包/类
@Override
public void initialize() {
Gauge.builder(NAME_HYSTRIX_CIRCUIT_BREAKER_OPEN, circuitBreaker, c -> c.isOpen() ? 1 : 0)
.tags(tags).register(meterRegistry);
HystrixCommandCompletionStream.getInstance(commandKey)
.observe()
.subscribe(hystrixCommandCompletion -> {
/*
our assumptions about latency as returned by hystrixCommandCompletion:
# a latency of >= 0 indicates that this the execution occurred.
# a latency of == -1 indicates that the execution didn't occur (default in execution result)
# a latency of < -1 indicates some clock problems.
We will only count executions, and ignore non-executions with a value of -1.
Latencies of < -1 are ignored as they will decrement the counts, and Prometheus will
take this as a reset of the counter, therefore this should be avoided by all means.
*/
long totalLatency = hystrixCommandCompletion.getTotalLatency();
if (totalLatency >= 0) {
Timer.builder(NAME_HYSTRIX_LATENCY_TOTAL)
.tags(tags)
.register(meterRegistry)
.record(totalLatency, TimeUnit.MILLISECONDS);
} else if (totalLatency < -1) {
LOG.warn("received negative totalLatency, event not counted. " +
"This indicates a clock skew? {}",
hystrixCommandCompletion);
}
long executionLatency = hystrixCommandCompletion.getExecutionLatency();
if (executionLatency >= 0) {
Timer.builder(NAME_HYSTRIX_LATENCY_EXECUTION)
.tags(tags)
.register(meterRegistry)
.record(executionLatency, TimeUnit.MILLISECONDS);
} else if (executionLatency < -1) {
LOG.warn("received negative executionLatency, event not counted. " +
"This indicates a clock skew? {}",
hystrixCommandCompletion);
}
for (HystrixEventType hystrixEventType : HystrixEventType.values()) {
int count = hystrixCommandCompletion.getEventCounts().getCount(hystrixEventType);
if (count > 0) {
switch (hystrixEventType) {
/* this list is derived from {@link HystrixCommandMetrics.HealthCounts.plus} */
case FAILURE:
case TIMEOUT:
case THREAD_POOL_REJECTED:
case SEMAPHORE_REJECTED:
Counter.builder(NAME_HYSTRIX_ERRORS)
.tags(tags)
.register(meterRegistry)
.increment(count);
case SUCCESS:
Counter.builder(NAME_HYSTRIX_REQUESTS)
.tags(tags)
.register(meterRegistry)
.increment(count);
break;
}
if(executionEvents.contains(hystrixEventType)) {
getExecutionCounter(hystrixEventType).increment(count);
} else if(fallbackEvents.contains(hystrixEventType)){
getFallbackCounter(hystrixEventType).increment(count);
} else {
getOtherExecutionCounter(hystrixEventType).increment(count);
}
}
}
});
String threadPool = metrics.getThreadPoolKey().name();
Gauge.builder(NAME_HYSTRIX_THREADPOOL_CONCURRENT_EXECUTION_CURRENT, metrics, HystrixCommandMetrics::getCurrentConcurrentExecutionCount)
.tags(Tags.concat(tags, "threadpool", threadPool))
.register(meterRegistry);
Gauge.builder(NAME_HYSTRIX_THREADPOOL_CONCURRENT_EXECUTION_ROLLING_MAX, metrics, HystrixCommandMetrics::getRollingMaxConcurrentExecutions)
.tags(Tags.concat(tags, "threadpool", threadPool))
.register(meterRegistry);
}