1. 程式人生 > >Spring-cloud 微服務架構搭建 04 - Hystrix 監控配合turbine的配置使用

Spring-cloud 微服務架構搭建 04 - Hystrix 監控配合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介面,彈出以下畫面
    Hystrix監控畫面

  • 在輸入行中輸入http://localhost:8091/turbine.stream 進入叢集監控畫面,如下:
    turbine叢集監控畫面

注意:我們在第一次進入時畫面顯示為loading…,只有在訪問了介面之後才會出現上面的畫面,監控臺上的控制資訊詳細說明可以網上查詢資料……^ _ ^

turbine可以繼承amqp使用訊息佇列進行資訊監控,只需要修改spring-cloud-starter-netflix-turbinespring-cloud-starter-netflix-turbine-amqp,然後進行rabbitmq的配置後就可以使用了,但是得確保訊息佇列的啟動無誤。

本文github程式碼地址:
spring-cloud 基礎模組搭建 – 歡迎指正