1、新建cloud-consumer-hystrix-dashboard9001 2、改pom
<dependencies> <!--新增hystrix dashboard--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>3、写yml
server: port: 90014、主启动类
@SpringBootApplication @EnableHystrixDashboard public class HystrixDashboardMain9001 { public static void main(String[] args) { SpringApplication.run(HystrixDashboardMain9001.class,args); } }5、所有Provider微服务提供类(8001/8002/8003)都需要监控依赖配置
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>6、启动:http://localhost:9001/hystrix
1、修改cloud-provider-hystrix-payment8001 注意:新版本Hystrix需要在主启动类MainAppHystrix8001中指定监控路径,否则会报错Unable to connect to Command Metric Stream
@SpringBootApplication @EnableEurekaClient @EnableCircuitBreaker public class PaymentHystrixMain8001 { public static void main(String[] args) { SpringApplication.run(PaymentHystrixMain8001.class,args); } /** * 个人情况:要先触发fallback后,dashboard才会显示数据,否则为loading!!!!! * @return */ @Bean public ServletRegistrationBean getServlet(){ HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; } }2、监控测试 ①启动1个eureka或者3个eureka集群均可 ②观察监控窗口
1、9001监控8001 ①填写监控地址:http://localhost:8001/hystrix.stream ② 2、测试地址(我这里有点BUG,要先执行会抛出异常的方法②,监控面板才会有反应) ①http://localhost:8001/payment/circuit/31 ②http://localhost:8001/payment/circuit/-31 ③先访问正确地址,再访问错误地址,再正确地址,会发现图示断路器都是慢慢放开的 监控结果,成功 监控结果,失败
3、如何看 7色
1圈 1线 曲线:用来记录2分钟内流量的相对变化,可以通过它来观察到流量的上升和下降趋势。
整图说明 整图说明2