Version: Next

图形化服务监控 Dashboard

准实时调用监控 Hystrix Dashboard

  • Hystrix 会持续记录所有通过 Hystrix 发起的请求的执行信息,以同级报表和图形的形式展示给用户
  • 包括 每秒执行请求数请求成功数请求失败数
  • Netfix 通过 hystrix-metrics-event-stream 项目实现对以上指标的监控
  • Spring Cloud 提供了对 Hystrix Dashboard 的整合

Cloud-consumer-hystrix-dashboard9001

pom

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

yaml

application.yaml
server:
port: 9001
spring:
application:
name: cloud-provider-hystrix-payment
#这里只把feign做客户端用,不注册进eureka
eureka:
client:
#表示是否将自己注册进EurekaServer默认为true
register-with-eureka: true
service-url:
defaultZone: http://localhost:7001/eureka
#defaultZone: http://eureka7001.com:7001/eureka/

主启动类

  • 添加 @EnableHystrixDashboard 注解
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardMain9001 {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardMain9001.class, args);
}
}

服务端 Provider

Pom

注意

所有的 Provider 微服务(8001、8002 等) 都需要监控依赖配置

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

yaml

  • 需要设置 management.endpoints.web.exposure.include: "*"
server:
port: 8001
spring:
application:
name: cloud-provider-hystrix-payment
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
#defaultZone: http://localhost:7001/eureka
defaultZone: http://eureka7001.com:7001/eureka/ # 配置在本机器 host 文件里
management:
endpoints:
web:
exposure:
include: "*"

测试

  • 运行 Cloud-consumer-hystrix-dashboard9001 项目
  • 访问 http://localhost:9001/hystrix 出现网页即表示 dashboard 运行成功

  • 启动注册中心 7001
  • 启动 provider8001
    • 访问 http://127.0.0.1:8001/payment/circuit/2http://127.0.0.1:8001/payment/circuit/-2,制造一些流量
  • 访问 localhost:9001/hystrix,在页面的输入框输入要监控的微服务,例如要监控 8001,则输入http://127.0.0.1:8001/actuator/hystrix.stream,点 Monitor Stream 按钮