(六)spring-cloud入门学习:断路器聚合监控(Hystrix Dashboard Turbine)

看单个的Hystrix Dashboard的数据并没有什么多大的价值,要想看这个系统的Hystrix Dashboard数据就需要用到Hystrix Turbine。Hystrix Turbine将每个服务Hystrix Dashboard数据进行了整合。

大概思路:
通过eureka-client注册到eureka-server,然后通过application.name获取到应用的监控数据,使用turbine进行整合后在Hystrix Dashboard展示。

在eureka_hystrix_dashboard工程进行调整
1. pom.xml在原本基础上增加了spring-cloud-starter-netflix-eureka-client和spring-cloud-starter-netflix-turbine.


  4.0.0

  com.kevin
  eureka_hystrix_dashboard
  0.0.1-SNAPSHOT
  jar

  eureka_hystrix_dashboard
  http://maven.apache.org

  
    UTF-8
  

  
    org.springframework.boot
    spring-boot-starter-parent
    2.1.4.RELEASE
  

  
    
        org.springframework.boot
        spring-boot-starter-web
    
    
        org.springframework.boot
        spring-boot-starter-test
        test
    
    
        org.springframework.cloud
        spring-cloud-starter-netflix-eureka-client
    
    
        org.springframework.cloud
        spring-cloud-starter-netflix-hystrix-dashboard
    
    
        org.springframework.cloud
        spring-cloud-starter-netflix-turbine
    
    
        org.springframework.boot
        spring-boot-starter-actuator
    
  
  
    
        
           org.springframework.cloud
           spring-cloud-dependencies
           Greenwich.SR1
           pom
           import
        
    
  

2. application.properties

spring.application.name=eurekaHystrixDashboard
server.port=9203

# 需要监听的应用名
turbine.appConfig=eurekaRibbon,eurekaFeign
turbine.clusterNameExpression=new String("default")
turbine.aggregator.clusterConfig= default

eureka.client.serviceUrl.defaultZone=http://localhost:9101/eureka/

3. Application.java

package com.kevin.eureka_hystrix_dashboard;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
@EnableDiscoveryClient
public class Application {
	
    public static void main( String[] args ) {
    	new SpringApplicationBuilder(Application.class)
    		.web(WebApplicationType.SERVLET).run(args);
    }
}

4. 启动eurekaServer,两个eurekaClient,两个消费者(eurekaRibbon和eurekaFeign),以及监控eurekaHystrixDashboard

1)查看eurekaServer:http://127.0.0.1:9101/
(六)spring-cloud入门学习:断路器聚合监控(Hystrix Dashboard Turbine)_第1张图片

2)查看HystrixDashboard:http://127.0.0.1:9203/hystrix
(六)spring-cloud入门学习:断路器聚合监控(Hystrix Dashboard Turbine)_第2张图片
3)输入http://127.0.0.1:9203/turbine.stream查看,分别监控了两个消费端
(六)spring-cloud入门学习:断路器聚合监控(Hystrix Dashboard Turbine)_第3张图片

备注:刚开始进来如果处于loading,分别访问一下两个消费者的接口http://127.0.0.1:9201/sayHello和http://127.0.0.1:9202/sayHello即可

你可能感兴趣的:(spring-cloud)