Hystrix Health Indicator及Metrics Stream

1. Health Indicator 健康指示器

连接的断路器的状态也暴露在调用应用程序的/health下,如下例所示:

{
    "hystrix": {
        "openCircuitBreakers": [
            "StoreIntegration::getStoresByLocationLink"
        ],
        "status": "CIRCUIT_OPEN"
    },
    "status": "UP"
}

下面我演示自己的实验:

项目启动:

1.microservice-discovery-eureka

security:
  basic:
    enabled: true
  user:
    name: user
    password: password123
server:
  port: 8761
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://user:password123@localhost:8761/eureka

2.microservice-provider-user

server:
  port: 7900
spring:
  jpa:
    generate-ddl: false
    show-sql: true
    hibernate:
      ddl-auto: none
  datasource:
    platform: h2
    schema: classpath:schema.sql
    data: classpath:data.sql
  application:
    name: microservice-provider-user
logging:
  level:
    root: INFO
    org.hibernate: INFO
    org.hibernate.type.descriptor.sql.BasicBinder: TRACE
    org.hibernate.type.descriptor.sql.BasicExtractor: TRACE
    com.itmuch: DEBUG
eureka:
  client:
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://user:password123@localhost:8761/eureka
  instance:
    prefer-ip-address: true
    instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
    metadata-map:
      zone: ABC      # eureka可以理解的元数据
      lilizhou: BBC  # 不会影响客户端行为
    lease-renewal-interval-in-seconds: 5

3. microservice-consumer-movie-ribbon-with-hystrix

spring:
  application:
    name: microservice-consumer-movie-ribbon-with-hystrix
server:
  port: 8010
eureka:
  client:
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://user:password123@localhost:8761/eureka
  instance:
    prefer-ip-address: true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000

请求地址:http://localhost:8010/health

请求:http://localhost:8010/movie/1 

 

 停掉用户微服务(microservice-provider-user),模拟用户微服务宕掉的情况

连续请求:http://localhost:8010/movie/1 

返回如下结果:

 再次请求http://localhost:8010/health如下结果:断路器打开

 2. Hystrix Metrics Stream

要启用Hystrix metrics流,需要包含对spring-boot-start -actuator的依赖,并设置management.endpoints.web.exposure.include: hystrix.stream。暴露/actuator/hystrix.stream下,依赖如下:(不加项目也

hystrix.stream其实是监控API情况,如下:

日志不停打出,也很难读,所用可用 Hystrix Dashboard做监控

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值