1. 現狀
目前Hystrix項目可以監控消費者,但是每一個消費者就需要啓動一個監控頁面,很不方便,可以通過Turbine實現一個監控頁面,監控多個消費者
2. 改造Dashbord項目
2.1 pom依賴
增加turbine的依賴,其它和單機dashbord一致
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
</dependencies>
2.2 yml配置
監控集羣需要從Eureka-Server獲取消費者服務
server:
port: 10001
eureka:
client:
serviceUrl:
defaultZone: http://eureka-server-7001:7001/eureka/,http://eureka-server-7002:7002/eureka/,http://eureka-server-7003:7003/eureka/
instance:
instance-id: eureka-consumer-hystrix-dashbord-10001 # 服務名稱
prefer-ip-address: true # 顯示ip地址
info: # 點擊註冊列表未服務出現的信息
app.name: springcloud
company.name: www.honor.com
build.artifactId: @project.artifactId@
build.version: @project.version@
spring:
application:
name: eureka-consumer-hystrix-dashbord
turbine:
combine-host-port: true
app-config: EUREKA-CONSUMER #需要監控的集羣名稱
aggregator:
cluster-config: default
cluster-name-expression: new String("default")
2.3 主啓動類
@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class EurekaConsumeHystrixDashbord10001 {
public static void main(String[] args) {
SpringApplication.run(EurekaConsumeHystrixDashbord10001.class, args);
}
}
2.4 測試
瀏覽器輸入http://localhost:10001/turbine.stream可以看到ping頁面表示成功
集羣監控