1、概述
除了隔离依赖服务的调用以外,Hystrix还提供了准实时的调用监控
(Hystrix Dashboard) ,Hystrix会持续地记录所有通过Hystrix发起的请求的执行信息,
并以统计报表和图形的形式展示给用户,并以统计报表和图形的形式展示给用户,
包括每秒执行多少请求多少成功,多少失败等。Netflix通过hystrix-metrics-event-stream项目
实现了对以上指标的监控。Spring Cloud也提供了Hystrix DashBoard的整合,对监控内容转换成可视化界面。
2、仪表盘9001
1、新建moudle
2、POM
<dependencies><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-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>
3、YML
server:port: 9001
4、主启动
3、断路器演示
1、修改8001
pom
<!--web--><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>
2、主启动类
{public static void main(String[] args) {SpringApplication.run(PaymentHystrixMain8001.class, args);}/***此配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑*ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",*只要在自己的项目里配置上下面的servlet就可以了*/@Beanpublic ServletRegistrationBean getServlet() {HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);registrationBean.setLoadOnStartup(1);registrationBean.addUrlMappings("/hystrix.stream");registrationBean.setName("HystrixMetricsStreamServlet");return registrationBean;}
需要在8001
填写Hystrix
@SpringBootApplication@EnableEurekaClient@EnableCircuitBreakerpublic class PaymentHystrixMain8001{public static void main(String[] args) {SpringApplication.run(PaymentHystrixMain8001.class, args);}/***此配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑*ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",*只要在自己的项目里配置上下面的servlet就可以了*/@Beanpublic ServletRegistrationBean getServlet() {HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);registrationBean.setLoadOnStartup(1);registrationBean.addUrlMappings("/hystrix.stream");registrationBean.setName("HystrixMetricsStreamServlet");return registrationBean;}}
监控测试
1、启动一个eureka或者3个eureka集群即可
2、观察监控窗口
9001监控8001
填写监控地址
测试地址
如何看?
7色
1圈
实心圈:共有两种含义。通过颜色的变化代表了实例的健康程度,它的健康度从绿色<黄色<橙色<红色递减。
该实心圆除了颜色的变化之外,它的大小也会根据实例的请求流量发生变化,流量约到该实心圆就越大。所以通过该实心圆的展示,就快速的发现故障实例和高压力实例
