在restTemplate 中使用Hystrix Dashboard
==================================
修改eureka-client-ribbon 项目,添加依赖:
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-netflix-hystrix-dashboard
在启动类EurekaClientRibbonApplication上添加注解@EnableHystrixDashboard。
@EnableHystrixDashboard
@EnableHystrix
@EnableEurekaClient
@SpringBootApplication
@ComponentScan(“com.springcloud.demo.eurekaclientribbon”)
public class EurekaClientRibbonApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientRibbonApplication.class, args);
}
}
还需要添加ServletRegistrationBean ,这是新版本做的修改,这里在RibbonConfig中添加。
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings(“/actuator/hystrix.stream”);
registrationBean.setName(“HystrixMetricsStreamServlet”);
return registrationBean;
}
启动eureka-server,eureka-client,eureka-client-riibon,浏览器请求http://localhost:8795/hystrix
在界面上分别输入http://localhost:8795/actuator/hystrix.stream,2000,ribbon,点击Monitor Stream,界面出现两个loading。。。请求http://localhost:8795/main调用eureka-client中的服务。
界面如上图。多次点击后灰色的小圆圈会变大,直线会上扬,具体效果自己验证。
在feign中的配置与ribbon 相同,这里不再赘述。
使用Turbine 中聚合监控
===============
在使用 Hystrix Dashboard组件监控服务的熔断器状况时,每个服务都有Dashboard主页,当服务数量很多时,监控非常不方便。为了同时监控多个服务的熔断器的状Turbine用于聚合多个 Hystrix Dashboard, Netflix开源了 Hystrix的另一个组件 Turbine
将多个 Hystrix Dashboard组件的数据放在一个页面上展示,进行集中监控。
创建新的Module eureka-monitor-client
pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?><project xmlns=“http://maven.apache.org/POM/4.0.0” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
4.0.0
com.springcloud.demo
springcloud-demo
1.0-SNAPSHOT
eureka-monitor-client
0.0.1-SNAPSHOT
jar
eureka-monitor-client
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
最后
由于文案过于长,在此就不一一介绍了,这份Java后端架构进阶笔记内容包括:Java集合,JVM、Java并发、微服务、SpringNetty与 RPC 、网络、日志 、Zookeeper 、Kafka 、RabbitMQ 、Hbase 、MongoDB、Cassandra 、Java基础、负载均衡、数据库、一致性算法、Java算法、数据结构、分布式缓存等等知识详解。
本知识体系适合于所有Java程序员学习,关于以上目录中的知识点都有详细的讲解及介绍,掌握该知识点的所有内容对你会有一个质的提升,其中也总结了很多面试过程中遇到的题目以及有对应的视频解析总结。
bUid-1714455432528)]
本知识体系适合于所有Java程序员学习,关于以上目录中的知识点都有详细的讲解及介绍,掌握该知识点的所有内容对你会有一个质的提升,其中也总结了很多面试过程中遇到的题目以及有对应的视频解析总结。
[外链图片转存中…(img-Lq4psuaV-1714455432529)]
[外链图片转存中…(img-kGKv34Wb-1714455432529)]