1. 程式人生 > >hystrix源碼小貼士之Yammer Publisher

hystrix源碼小貼士之Yammer Publisher

ron pub spa publish size csp cte .get group

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