Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。但是只使用Hystrix Dashboard的话, 你只能看到单个应用内的服务信息, 这明显不够. 我们需要一个工具能让我们汇总系统内多个服务的数据并显示到Hystrix Dashboard上, 这个工具就是Turbine.
Turbine
一:build.gradle 引入jar
dependencies { compile "org.springframework.cloud:spring-cloud-starter-hystrix", "org.springframework.cloud:spring-cloud-starter-hystrix-dashboard", "org.springframework.boot:spring-boot-starter-actuator", "org.springframework.cloud:spring-cloud-starter-turbine" }
二:修改启动类 添加@EnableHystrixDashboard @EnableTurbine 激活对Turbine的支持
@SpringBootApplication @EnableHystrixDashboard @EnableTurbine public class DemoturbineApplication { public static void main(String[] args) { SpringApplication.run(DemoturbineApplication.class, args); } }
三:修改application.properties配置文件
spring.application.name=hystrix-dashboard-turbine server.port=9111 turbine.appConfig=node1,node2 turbine.aggregator.clusterConfig= default turbine.clusterNameExpression= new String("default") eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
四 启动项目
顺序分别为 eureka , consume , turbine 启动成功
五改造原来consume项目
修改build.gradle 文件
dependencies { compile "org.springframework.cloud:spring-cloud-starter-feign", "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client", "org.springframework.boot:spring-boot-devtools", "org.springframework.boot:spring-boot-starter-test", "org.springframework.cloud:spring-cloud-starter-hystrix", "org.springframework.cloud:spring-cloud-starter-hystrix-dashboard", "org.springframework.boot:spring-boot-starter-actuator" }
六 修改配置文件
spring.application.name=node1 server.port=9221 #熔断器生效 feign.hystrix.enabled=true eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
spring.application.name=node2 server.port=9222 #熔断器生效 feign.hystrix.enabled=true eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/
七:修改启动类
@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients @EnableHystrixDashboard @EnableCircuitBreaker public class ConsumeApplication { public static void main(String[] args) { SpringApplication.run(ConsumeApplication.class, args); } }
八:修改原来得Remote,HelloRemoteHystrix, Controller
@FeignClient(name= "spring-cloud-producer2" ,fallback = HelloRemoteHystrix.class) public interface HelloRemote { @RequestMapping(value = "/hello") String hello2(@RequestParam(value = "name") String name); @RequestMapping(value = "/hello1") String hello1(@RequestParam(value = "name") String name); }
启动项目 顺序分别为 eureka,node1,node2, turbine
服务中心都已注册
访问hystrix 在浏览器输入 http://localhost:9111/hystrix
接下来监控,两个节点集群使用第一个地址,可根据名字来监控具体得项目,单个项目使用第三个地址,我们使用第一个地址
返回结果