接上一章节Hystrix Dashboard仪表盘监控服务搭建,这里讲讲服务消费者构建Hystrix Dashboard监控端点
Hystrix 仪表盘工程已经创建好了,现在我们需要有一个服务,让这个服务提供一个路径为/actuator/hystrix.stream 接口,然后就可以使用 Hystrix 仪表盘来对该服务进行监控了;
1、服务消费者项目需要有 hystrix 的依赖(之前已经加好了):
org.springframework.cloud spring-cloud-starter-netflix-hystrix 2.1.0.RELEASE
2、服务消费者项目需要有一个 spring boot 的服务监控依赖:
org.springframework.boot spring-boot-starter-actuator
3、配置文件需要配置 spring boot 监控端点的访问权限:
#springboot的监控端点访问权限,*表示所有的访问端点都允许访问
management.endpoints.web.exposure.include=*
这个是用来暴露 endpoints 的,由于 endpoints 中会包含很多敏感信息,除
了 health 和 info 两个支持直接访问外,其他的默认不能直接访问,所以我们
让它都能访问,或者指定:
management.endpoints.web.exposure.include=hystrix.stream
@Beanpublic ServletRegistrationBean getServlet() {HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);registrationBean.setLoadOnStartup(1);registrationBean.addUrlMappings("/actuator/hystrix.stream");//访问路径registrationBean.setName("hystrix.stream");return registrationBean;}
– 再次访问入口 http://localhost:8081/actuator/hystrix.stream
注意:这里有一个细节需要注意,要访问/hystrix.stream 接口,首先得访问
consumer 工程中的任意一个其他接口,否则直接访问/hystrix.stream 接口时
会输出出一连串的 ping: ping: …,先访问 consumer 中的带有熔断器的任意一个其他接口,
然后再访问/hystrix.stream 接口即可;
hystrix.dashboard.proxy-stream-allow-list=localhost
参数详解:
OK,仪表盘已经显示出来了,那么仪表盘上的各项数据都是什么意思呢?我们来看下面一张图:
上一篇:java中的进程和线程的问题