SpringCloud Hystrix Dashboard
Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。
监控服务pom配置文件
<!--系统注册与监控服务--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <!--hystrix仪表盘--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency>
application.properties
server.port=8070 spring.application.name=claimdashboard eureka.client.service-url.defaultZone=http://localhost:8091/eureka/ eureka.client.registerWithEureka=true eureka.client.fetchRegistry=true
@SpringBootApplication @EnableHystrixDashboard public class ClaimdashboardApplication { /* 启动输入http://localhost:8070/hystrix 再输入某个需要监控的服务 http://localhost:8030/hystrix.stream */ public static void main(String[] args) { SpringApplication.run(ClaimdashboardApplication.class, args); } }
被监控服务的配置
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
#服务名称 spring.application.name=claimaudit #配置服务中心注册地址 eureka.client.service-url.defaultZone=http://localhost:8091/eureka/ eureka.client.instance.lease-renewal-interval-in-seconds=30 feign.hystrix.enabled=true
@SpringBootApplication @EnableDiscoveryClient //注册服务 @EnableFeignClients //开启feign @EnableHystrix //开启断路器 @EnableCircuitBreaker public class ClaimauditApplication { public static void main(String[] args) { SpringApplication.run(ClaimauditApplication.class, args); } }
主要是下面这段代码,如果不添加监控服务会报连接不上的错误
@Configuration public class HystrixConfig { @Bean public HystrixMetricsStreamServlet hystrixMetricsStreamServlet(){ return new HystrixMetricsStreamServlet(); } @Bean public ServletRegistrationBean registration(HystrixMetricsStreamServlet servlet){ ServletRegistrationBean registrationBean = new ServletRegistrationBean(); registrationBean.setServlet(servlet); //是否启用该registrationBean registrationBean.setEnabled(true); registrationBean.addUrlMappings("/hystrix.stream"); return registrationBean; } }