赞
踩
- 新版本中有一些更新,如果还用旧版本的方式,会有不少问题
- 当前版本:
spring-cloud 2021.0.0
,spring-boot 2.6.3
,hystrix 和 dashboard 2.2.10
dashboard
模块
springcloud-consumer-hystrix-dashboard-9001
监控模块
<!-- spring-cloud-starter-netflix-hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<!-- 版本号由父类 dependencyManagement 管理 -->
<!-- <version>2.2.10.RELEASE</version> -->
</dependency>
<!-- spring-cloud-starter-netflix-hystrix-dashboard -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.2.10.RELEASE</version>
</dependency>
@EnableHystrixDashboard
开启监控功能
@SpringBootApplication
@EnableHystrixDashboard
public class DepartmentConsumerDashboard_9001 {
public static void main(String[] args) {
SpringApplication.run(DepartmentConsumerDashboard_9001.class,args);
}
}
proxy-stream-allow-list: "*"
在新版本中需要配置这个
server:
port: 9001
hystrix:
dashboard:
proxy-stream-allow-list: "*"
被监控的方法需要有熔断功能
actuator
、hystrix
<!-- actuator完善监控信息 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- spring-cloud-starter-netflix-hystrix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
在主启动类中添加如下方法:
两个方法选一个就可以
@Bean
public ServletRegistrationBean hystrixMetricsStreamServlet() {
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
// 监控服务的地址
servletRegistrationBean.addUrlMappings("/actuator/hystrix.stream");
return servletRegistrationBean;
}
/* @Bean
public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}*/
- 主启动类上不需要再添加新注解
- application.yml 中不需要增加配置;不用设为
include: "*"
# 监控端口配置
management:
endpoints:
web:
exposure:
# 开启 info,health;新版本中只默认开启了 health
include: info,health
#
#include: "*"
启动
熔断服务提供者
监控页
需要注意的几个点
proxy-stream-allow-list: "*"
熔断服务
主机名
,不要用ipCopyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。