概述
actuator可以监控应用状态,但数据展示不直观,springboot admin、hystrix dashboard、turbine都集成了actuator,并提供了UI界面来展示应用状态。
springboot admin、hystrix dashboard、turbine都可以监控应用,但监控的维度不同
- springboot admin:关注应用本身的状态,可以监控所有服务,可以看到cpu、内存、线程、硬盘、jvm的情况,可以看到应用输出的日志
- hystrix dashboard:关注服务之间的调用情况,服务消费者 -> 服务提供者,监控的是服务消费者。以节点为单位进行监控,不能统计服务集群的信息
- turbine:和hystrix dashboard基本一样,区别是turbine是以集群为单位进行监控,可以看到服务集群的整体信息
hystrix dashboard的使用
依赖
- Spring Cloud Discovery -> Eureka Discovery Client
- Spring Cloud Circuit Breaker -> Hystrix DashBoard [Maintenance]
也可以手动添加依赖
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><!-- 包含了spring-boot-start-web、spring-boot-starter-actuator --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId></dependency>
单独作为一个服务只需要添加这两个依赖即可,如果不注册到eureka server上,也可以不要eureka client,但更推荐都把服务注册到注册中心上,通过网关统一访问。
引导类
加@EnableEurekaClient、@EnableHystrixDashboard
yml
server:port:7501spring:application:name: hystrix-dashboardeureka:client:service-url:defaultZone: http://localhost:7500/eureka/#允许访问dashboard的web页面hystrix:dashboard:#也可以指定具体的域名|ipproxy-stream-allow-list:"*"
运行
启动应用,访问 localhost:7501/hystrix (hystrix dashboard的ip:port)进入hystrix dashboard的页面。
输入要监控的服务消费者的流,eg. http://localhost:8781/actuator/hystrix.stream
turbine的使用
依赖
勾选Spring Cloud Circuit Breaker的2个依赖
- Hystrix DashBoard [Maintenance]
- Turbine [Maintenance]
也可以手动添加依赖
<!-- 已经包含了spring-boot-start-web、spring-boot-starter-actuator --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId></dependency><!-- 已经包含了eureka client --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-turbine</artifactId></dependency>
只添加这2个依赖即可。
turbine监控的服务集群信息是对hystrix dashboard监控的服务节点信息的聚合、统计,是建立在hystrix dashboard之上的,使用的仍是hystrix dashboard的web页面。
引导类
加@EnableEurekaClient、@EnableHystrixDashboard、@EnableTurbine
yml
server:port:7502spring:application:name: turbineeureka:client:service-url:defaultZone: http://localhost:7500/eureka/#允许访问dashboard的web页面hystrix:dashboard:#也可以指定具体的域名|ipproxy-stream-allow-list:"*"turbine:#要监控的服务,有多个时逗号分隔app-config: user-server,order-servercluster-name-expression: new String("default")#以host+port区分服务节点。默认只以host来区分服务节点combine-host-port:true
运行
启动应用,访问 localhost:7502/hystrix (turbine的ip:port)进入turbine的页面。
输入turbine的流,eg. http://localhost:7501/turbine.stream,会显示yml中配置的所有服务集群的信息。
说明
- hystrix dashboard是输入要监控的服务节点的流,http://localhost:7504(要监控的服务节点的host+port)/actuator/hystrix.stream
- turbine是输入turbine自身的流,http://localhost:7502(turbine本身的host+port)/turbine.stream
可直接在浏览器地址栏输入流的url查看原始数据。