服务监控HystrixDashboard
hystrix除了服务隔离外,还提供了服务监控hystrix会持续的将通过hystrix发起的请求信息以报表图形的形式展示给用户,如每秒执行了多少请求成功多少,失败多少等等
如何配置:
第一步 准备一个监控服务 zt-frank-consumer-hystrix-dashboard-service-5001
第二步 添加监控面板的的相关依赖
<!--熔断器Hystrix-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<!--熔断服务监控面板-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
注意
:要实现监控还需要健康检查的依赖包
<!-- actuator 健康检查 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
第三步 主启动类上添加开启监控面板的注解 @EnableHystrixDashboard
@SpringBootApplication
//hystrix熔断监控面板
@EnableHystrixDashboard
public class ZtFrankConsumerHystrixDashboardServiceApplication5001 {
private static Logger logger = Logger.getLogger(ZtFrankConsumerHystrixDashboardServiceApplication5001.class);
public static void main(String[] args) {
SpringApplication.run(ZtFrankConsumerHystrixDashboardServiceApplication5001.class, args);
logger.info("*********ZtFrankConsumerHystrixDashboardServiceApplication5001启动成功*********");
}
}
到这里监控服务就配置完成了。。。。。。。
第四步 启动监控服务5001,和需要被监控的服务8002
然后在浏览器上访问8002需要被监控服务hystrix的json监控报文
http://localhost:8002/hystrix.stream
呃呃呃 报错了

解决:然后在网上找了一下解决方案 因为版本原因需要在需要被监控的服务上的(也就是8002的服务)主启动类上加上配置
@SpringBootApplication
@EnableEurekaClient
/**
* 开启Feign调用接口的方式
*/
@EnableFeignClients(basePackages = {"com.zt.frank.consumerservice.service"})
/**
* hystrix服务熔断开启
*/
@EnableCircuitBreaker
//@ComponentScan("com.zt.frank.consumerservice.service")
public class ZtFrankConsumerFeignServiceApplication8002 {
private static Logger logger = Logger.getLogger(ZtFrankConsumerFeignServiceApplication8002.class);
public static void main(String[] args) {
SpringApplication.run(ZtFrankConsumerFeignServiceApplication8002.class, args);
logger.info("*********ZtFrankConsumerFeignServiceApplication8002启动成功*********");
}
//hystrixDasboard熔断显示面板 spring2.0之后一定要加这个。不然得不到监控的json报文
@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
//这个是访问路径可以修改,addUrlMappings配置的是什么,监控面板的需要被监控的url就是什么,比如这里,就是:http://localhost:8002/hystrix.stream
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}
第五步:重启需要被监控的服务8002,并在浏览器上访问 http://localhost:8002/hystrix.stream ,得到下图就说已经监控成功了

第六步:上图就被监控服务接口调用的监控信息,是json报文内容非常的不直观,友好,所以我们需要用到最开始配置配置的监控服务5001,它会将这些报文转换为更为直观的报表 浏览器请求监控服务 http://localhost:5001/hystrix

初次学习网上找的解释图:。。。。。

426

被折叠的 条评论
为什么被折叠?



