1. 程式人生 > >如何配置:斷路器Dashboard監控儀表盤

如何配置:斷路器Dashboard監控儀表盤

斷路器Dashboard監控儀表盤:如圖

這個東西是怎麼配置和訪問的呢?

 

1.加入依賴

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

 

2、啟動類增加註解
        @EnableHystrixDashboard

package net.xdclass.order_service;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; @SpringBootApplication @EnableFeignClients @EnableCircuitBreaker @EnableHystrixDashboard
public class OrderServiceApplication { public static void main(String[] args) { SpringApplication.run(OrderServiceApplication.class, args); } @Bean @LoadBalanced public RestTemplate restTemplate() { return new RestTemplate(); } }

 

3、配置檔案增加endpoint
management:
  endpoints:
    web:
      exposure:
        include: "*"

server:
  port: 8781


#指定註冊中心地址
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

#服務的名稱
spring:
  application:
    name: order-service
  redis:
    database: 0
    host: 127.0.0.1
    port: 6379
    timeout: 2000

#自定義負載均衡策略
product-service:
  ribbon:
    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule


#修改呼叫超時時間
feign:
  hystrix:
    enabled: true
  client:
    config:
      default:
        connectTimeout: 4000
        readTimeout: 4000

#把hystrix超時時間禁用
#hystrix:
#  command:
#    default:
#      execution:
#        timeout:
#          enabled: false

#execution.isolation.thread.timeoutInMilliseconds=4000

#設定超時時間
hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 1000
            
#斷路器Dashboard監控儀表盤
management:
  endpoints:
    web:
      exposure:
        include: "*"

4、訪問入口
        http://localhost:8781/hystrix
        Hystrix Dashboard輸入: http://localhost:8781/actuator/hystrix.stream 

參考資料
        預設開啟監控配置
        https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-security-actuator

        配置檔案類:
            spring-configuration-metadata.json