hystrix源码小贴士之Yammer Publisher

Posted zwh1988

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hystrix源码小贴士之Yammer Publisher相关的知识,希望对你有一定的参考价值。

HystrixYammerMetricsPublisher

  继承HystrixMetricsPublisher,创建HystrixYammerMetricsPublisherCommand、HystrixYammerMetricsPublisherThreadPool、HystrixYammerMetricsPublisherCollapser。

 @Override
    public HystrixMetricsPublisherCommand getMetricsPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) {
        return new HystrixYammerMetricsPublisherCommand(commandKey, commandGroupKey, metrics, circuitBreaker, properties, metricsRegistry);
    }

    @Override
    public HystrixMetricsPublisherThreadPool getMetricsPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, HystrixThreadPoolProperties properties) {
        return new HystrixYammerMetricsPublisherThreadPool(threadPoolKey, metrics, properties, metricsRegistry);
    }

    @Override
    public HystrixMetricsPublisherCollapser getMetricsPublisherForCollapser(HystrixCollapserKey collapserKey, HystrixCollapserMetrics metrics, HystrixCollapserProperties properties) {
        return new HystrixYammerMetricsPublisherCollapser(collapserKey, metrics, properties, metricsRegistry);
    }

 HystrixYammerMetricsPublisherCommand

  从HystrixCommandMetrics获取数据,然后设置到MetricsRegistry中。

例如:

protected void createExecutionLatencyPercentileGauge(final String name, final double percentile) {
        metricsRegistry.newGauge(createMetricName(name), new Gauge<Integer>() {
            @Override
            public Integer value() {
                return metrics.getExecutionTimePercentile(percentile);
            }
        });
    }

 HystrixYammerMetricsPublisherThreadPool

  从HystrixThreadPoolMetrics获取数据,然后设置到MetricsRegistry中。

例如:

metricsRegistry.newGauge(createMetricName("rollingMaxActiveThreads"), new Gauge<Number>() {
            @Override
            public Number value() {
                return metrics.getRollingMaxActiveThreads();
            }
        });

HystrixYammerMetricsPublisherCollapser

  从HystrixCollapserMetrics获取数据,然后设置到MetricsRegistry中。

例如:

metricsRegistry.newGauge(createMetricName("shardSize_percentile_50"), new Gauge<Integer>() {
            @Override
            public Integer value() {
                return metrics.getShardSizePercentile(50);
            }
        });

 

以上是关于hystrix源码小贴士之Yammer Publisher的主要内容,如果未能解决你的问题,请参考以下文章

hystrix源码小贴士之调用异常处理

hystrix源码小贴士之调用timeout实现

hystrix源码小贴士之之hystrix-metrics-event-stream

hystrix源码小贴士之命令四种调用方式的异同

hystrix源码小贴士之中断

unity开发小贴士之八 Audio使用心得