最近学习Hystrix时用到Hystrix DashBoard工具,Hystrix用于服务降级,服务限流,服务熔断,有一个Hystrix DashBoard工具可以监测使用了Hystrix的服务的状态。这里记录一下这玩意的配置,做个总结。
这里笔者用之前建立的模块 cloud-consumer-hystrix-dashboard9001 为例
这里列举重要的dependency,此外还需要服务注册,笔者用的是Eureka
<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-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency>复制代码
3. 配置application.yml
server: port: 9001 eureka: instance: hostname: localhost ... ... spring: application: name: hystrix-dashboard复制代码
简单的配置后就可以启动9001 HystrixDashBoard服务了
浏览器输入 http://localhost:9001/hystrix,成功访问
通过Hystrix Dashboard主页面的文字介绍,我们可以知道,Hystrix Dashboard共支持三种不同的监控方式
看一下Eureka服务注册中心,注册成功了
选定要注册监控的服务这个服务必须要使用了Hystrix,不然会一直loading..然后报错 Unable to connect to Command Metric Stream
这里笔者就用原先配置好的Hystrix服务降级 cloud-provider-hystrix-payment8005
浏览器返回 http://localhost:9001/hystrix
不出意外就的话,就出来了,YEAH!o(* ̄▽ ̄*)ブ
当然,可能没那么顺利 ≡(▔﹏▔)≡
可能还会出现这个BUG,原因是spring cloud版本升级后出现的BUG,笔者用的Hoxton.SR1就会 ( ̄、 ̄)
解决办法是在 8005这个要被监听的服务的主启动类上添加下面的代码
@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; } 复制代码
就像这样,之后就能正常访问了
至于启动后要怎么使用这个hystrix.stream就要大家去参考官网或者其他资料了
希望对你有帮助!(~ ̄▽ ̄)~