springcloud實戰之9 斷路器-叢集監控(turbine)
阿新 • • 發佈:2018-12-31
上一篇介紹了單例的服務監控,本章介紹對叢集的監控。通過引入turbine,通過它來彙集監控資訊,並將聚合後的資訊提供給Hystrix Dashboard來集中展示和監控。
其工作架構圖如下:
構建springcloud-hystrix-turbine專案
引入依賴
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version >1.5.9.RELEASE</version>
<relativePath />
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version >Edgware.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId >
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
建立執行入口
@SpringBootApplication
@EnableDiscoveryClient
@EnableTurbine
public class SpringCloudHystrixTurbineApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(SpringCloudHystrixTurbineApplication.class).web(true).run(args);
}
}
EnableDiscoveryClient宣告是eureka client
EnableTurbine申明啟用叢集監控
建立配置檔案
server:
port: 8006
management:
port: 8007
spring:
application:
name: springcloud-hystrix-turbine
eureka:
client:
service-url:
defaultZone: http://peer1:8080/eureka/
instance:
lease-renewal-interval-in-seconds: 30
lease-expiration-duration-in-seconds: 90
turbine:
app-config: springcloud-hystrix-dashboard # 指定了需要收集監控資訊的服務名
cluster-name-expression: new String('default') # 指定叢集名稱
combine-host-port: true # 設定為true,可以讓同一主機上的服務通過主機名與埠號的組合來進行區分,
啟動專案
1.啟動服務註冊中心叢集(springcloud-server-eureka)
2.啟動服務提供者(springcloud-producer-rest)
3.啟動服務消費者(springcloud-hystirx-dashboard)
4.啟動服務叢集監控者(springcloud-hystrix-turbine)
啟動後的註冊服務圖如下