當前位置: 首頁>>代碼示例>>Java>>正文


Java HystrixCommandCompletionStream類代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:ringcentral,項目名稱:hystrix-addons,代碼行數:9,代碼來源:AggregatedHystrixCommandCompletionStream.java

示例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);

}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:82,代碼來源:MicrometerMetricsPublisherCommand.java


注:本文中的com.netflix.hystrix.metric.HystrixCommandCompletionStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。