spring cloud(五) hystrix
2024-10-01 04:16:32
开启feign 熔断 hystrix 整合hystrix-dashboard监控面板
1. 服务调用者boot工程 pom引入依赖
<!-- hystrix-dashboard 监控依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2. 启动类开启熔断注解 @EnableCircuitBreaker 面板监控注解 @EnableHystrixDashboard 添加面板servlet
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableCircuitBreaker
@EnableHystrixDashboard
public class WebWapApplication { public static void main(String[] args) {
SpringApplication.run(WebWapApplication.class, args);
} @Bean
@LoadBalanced
RestTemplate restTemplate(){
return new RestTemplate();
} @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;
} }
3.修改配置文件 开启feign熔断 设置超时时间
feign.hystrix.enabled=true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=20000
4.浏览器查看面板监控 http://localhost:8080/hystrix
点击Monitor Stream 可查看请求成功次数 超时次数 等等
整合多个服务 分布式监控 使用 Turbine
1.新建boot工程 引入依赖
<!-- eureka客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> <!-- hystrix 监控面板 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-turbine</artifactId>
</dependency>
2.启动类添加注解
@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableTurbine
public class HystrixDashboardApplication { public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
@Bean
@LoadBalanced
RestTemplate restTemplate(){
return new RestTemplate();
} @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;
}
}
3. 配置文件
server.port=9004
spring.application.name=hystrix-dashboard
#eureka
eureka.client.service-url.defaultZone=http://localhost:9001/eureka/
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port} management.endpoints.web.exposure.include=hystrix.stream,health,info #要监控的服务name
turbine.app-config=web-wap turbine.cluster-name-expression=new String("default")
management.endpoint.health.show-details=always
management.health.redis.enabled=false
4.启动 查看面板
最新文章
- Nagios学习笔记四:基于NRPE监控远程Linux主机
- 最近的shell脚本(updating)
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- hadoop-2.6.0为分布式安装
- Global.asax使用1
- Scala基础入门-代码碎片
- JSP的学习(3)——语法知识二之page指令
- 用jQuery的ajax的功能实现输入自动提示的功能
- DevExpress 学习使用之 PrintSystem
- 【Sort】HeapSort
- 自然语言处理高手_相关资源_开源项目(比如:分词,word2vec等)
- JS的作用域浅谈
- HTML5-移动开发常用技巧与弹性布局的使用
- Go学习——new()和 make()的区别详解(转载)
- python使用魔法函数创建可切片类型
- 锐捷交换机配置DHCP SERVER给固定的MAC地址分配静态IP
- [转帖]NUMA架构的CPU -- 你真的用好了么?
- Http协议的理解
- 安装SourceTree遇到的一个个坑
- zabbix切换中文,监控图下方显示乱码,监控图X轴不显示时间问题解决(适用于所有版本)