1. 开启hystrix dashboard的监控
引入pom依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency>
启动类上开启@EnableHystrixDashboard和@EnableCircuitBreaker
@SpringCloudApplication @EnableHystrixDashboard public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
@SpringCloudApplication已经包含了@EnableCircuitBreaker
配置文件,不需要加特殊的配置
server: port: 50003 management: endpoints: web: exposure: include: "*" cors: allowed-origins: "*" allowed-methods: "*" eureka: instance: prefer-ip-address: true status-page-url-path: /actuator/info health-check-url-path: /actuator/health client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:50000/eureka/ spring: application: name: scfl-monitor-hystrix
启动后,访问:http://localhost:50003/hystrix
输入一个feign服务间调用,或者有hystrix filter的gateway地址,例http://localhost:50002/actuator/hystrix.stream,注意这里不是hystrix.stream,springboot2.0默认是actuator/hystrix.stream。
当50002的服务有hystrix调用时,这里才会出现图表。
2. 开启turbine监控
如果只开启hystrix的dashboard,监控每个服务的hystrix状态的话,需要一个一个服务去输入http://ip:port/actuator/hystrix.stream,非常麻烦。
通过turbine可以把所有服务的hystrix.stream聚合到一起,可以进行整体监控。
hystrix dashboard—->turbine.stream—>聚合集群下各个服务的hystrix.stream
turbine会把同一个conmmandKey的Hystrix命令合并
引入pom依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-turbine</artifactId> </dependency>
启动类上加上@EnableTurbine注解
@SpringCloudApplication @EnableHystrixDashboard @EnableTurbine public class App { public static void main(String[] args) { //new SpringApplicationBuilder(ServiceRegistryApplication.class).web(true).run(args); SpringApplication.run(App.class, args); } }
turbine的配置文件
turbine: app-config: scfl-service-gateway ##需要监控的服务名 aggregator: clusterConfig: default ##需要监控的服务集群名 clusterNameExpression: new String("default") combine-host: true instanceUrlSuffix: default: actuator/hystrix.stream ##key是clusterConfig集群的名字,value是hystrix监控的后缀,springboot2.0为actuator/hystrix.stream
启动引用,访问http://localhost:50003/hystrix,再输入http://localhost:50003/turbine.stream 进行监控
可以看到,如果用turbine的话,监控地址为本服务的ip+port+/turbine.stream,如果不用turbine的话,监控地址为各个服务的ip+port+/actuator/hystrix.stream
turbine配置文件详解
turbine监控服务的配置:turbine: app-config: i5xforyou-biz-kanjia,i5xforyou-service-gateway ##需要监控的服务名 aggregator: clusterConfig: kanjia,gateway ##需要监控的服务集群名,default clusterNameExpression: metadata['cluster'] ##new String("default") combine-host: true instanceUrlSuffix: kanjia: kanjia/actuator/hystrix.stream ##key为clusterConfig的集群名字,默认为default gateway: actuator/hystrix.stream ##value为集群的hystrix监控url后缀,springboot2.0默认为actuator/hystrix.stream
turbine被监控客户端的配置:需要配置集群名
eureka: instance: metadata-map: cluster: kanjia
default集群的stream路径为:http://ip:port/turbine.stream
有cluster的stream路径为:http://ip:port/turbine.stream?cluster=xxxxx