文章目錄
-
-
- 1. Hystrix儀表盤和Turbine叢集監控簡介
- 2. hystrix-dashboard-turbine 子產品快速搭建
-
1. Hystrix儀表盤和Turbine叢集監控簡介
Hystrix儀表盤主要監控hystrix中的各項名額資訊,以“桶”和“滾動時間窗的形式”,進行記錄儲存供外部調用。Hystrix儀表盤可以對單個服務進行監控,暴露hystrix.stream接口,Turbine整合所有服務進行監控。
2. hystrix-dashboard-turbine 子產品快速搭建
注:本文項目采用idea工具進行搭建
- 使用idea自身的spring initializr進行項目的初始化,項目名為:hystrix-dashboard-turbine。
- 初始化完成項目之後進行pom檔案導入
<!-- turbine 監控啟動類 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<!-- hystrix-dashboard 儀表盤啟動類 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<!-- 注冊eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- 修改bootstrap.yml檔案,添加如下配置:
management:
endpoints:
web:
exposure:
include: "*" # 暴露所有服務監控端口,也可以隻暴露 hystrix.stream端口
endpoint:
health:
show-details: ALWAYS
#eureka.client.serviceUrl.defaultZone屬性對應服務注冊中心的配置内容,指定服務注冊中心的位置。
eureka:
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: http://localhost:8761/eureka/
instance:
leaseRenewalIntervalInSeconds: 10
hostname: localhost
preferIpAddress: true
turbine:
# 1.被監控的服務應用沒有配置 context-path 的情況下
# 配置 Eureka 中的 serviceId 清單,指定要監控的服務
# app-config: SPRING-DEMO-SERVICE-FEIGN,SPRING-DEMO-SERVICE-RIBBON
# aggregator:
# cluster-config: default
# # 指定叢集名稱
# cluster-name-expression: "'default'"
# 2.被監控的服務應用配置了 context-path 的情況下,此時預設是叢集裡的應用都配置了 context-path
# 配置 Eureka 中的 serviceId 清單,指定要監控的服務
# app-config: SPRING-DEMO-SERVICE-FEIGN
# aggregator:
# cluster-config: default
# # 指定叢集名稱
# cluster-name-expression: "'default'"
# instanceUrlSuffix: gateway/actuator/hystrix.stream
# 3.被監控的服務應用一部配置設定置了 context-path,一部分沒有配置 context-path
# 配置 Eureka 中的 serviceId 清單,指定要監控的服務
app-config: feign-service,demo-service
aggregator:
cluster-config: default
# 指定叢集名稱
cluster-name-expression: "'default'"
combine-host-port: true
- 最後修改服務啟動類:
@EnableTurbine
@EnableHystrixDashboard
@SpringBootApplication
public class HystrixDashboardTurbineApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardTurbineApplication.class, args);
}
}
- 啟動項目,通路http://localhost:8091/hystrix接口,彈出以下畫面
- 在輸入行中輸入http://localhost:8091/turbine.stream 進入叢集監控畫面,如下:
注意:我們在第一次進入時畫面顯示為loading…,隻有在通路了接口之後才會出現上面的畫面,監控台上的控制資訊詳細說明可以網上查找資料……^ _ ^
turbine可以繼承amqp使用消息隊列進行資訊監控,隻需要修改spring-cloud-starter-netflix-turbine為spring-cloud-starter-netflix-turbine-amqp,然後進行rabbitmq的配置後就可以使用了,但是得確定消息隊列的啟動無誤。
本文github代碼位址:
spring-cloud 基礎子產品搭建 – 歡迎指正