第十九节--Hystrix图形化Dashboard

概述?
  除了隔离依赖服务的调用以外,Hystrix还提供了准时的调用监控(dashboard),hystrix会持续地记录所有通过hystrix发起的请求的执行信息
  ,并以报表和图像的形式展示给用户,包括每秒执行多少请求成功,多少失败等。对监控内容转化成可视化界面
 
操作
 
第一步:新建工程cloud-consumer-hystrix-dashboard9001 ,pom.xml新加依赖
<!--hystrix dashboard-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

第二步:yml文件

server:
  port: 9001
 
第三步:主启动类,启动图形界面监控@EnableHystrixDashboard
@EnableHystrixDashboard
@SpringBootApplication
public class HystrixDashboard {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboard.class,args);
}
}
第四步:启动项目9001,访问 http://localhost:9001/hystrix 即可
 
 
 
 
第五步:现在去监控cloud-provider-hystrix-payment8001工程,所监控的工程必须有下面两个包,否则监控不了
<!-- actuator监控信息完善 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
监控的工程也必须在主启动类加上一下代码,否则会提示说找不了监控,这是因为因为springboot升级到2.x版本之后存在的bug
/**
* 为了服务监控配置,与服务容错无关,springboot升级之后的bug
* ServletRegistrationBean因为springboot默认路径不是 /hystrix.stream
* 只要在自己需要监控的项目上配置一下即可
*/
@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;
}
第六步:9001去监控cloud-provider-hystrix-payment8001,启动一个eureka和这两个项目,访问上一节配置的容错方法,根据不同的id查找
  
多点击几次,如何去操作9001
 
id传正确时>0:容错是显示关闭Closed
 
 
id传错误<0时:容错是显示开启:Open
 
 
 
 
posted @ 2020-09-16 22:38  hexu_blog  阅读(185)  评论(0编辑  收藏  举报