【SpringCloud 2021.0.0】11、Hystrix + Dashboard 流监控 (spring-boot 2.6.3)

  • 新版本中有一些更新,如果还用旧版本的方式,会有不少问题
  • 当前版本:spring-cloud 2021.0.0spring-boot 2.6.3hystrix 和 dashboard 2.2.10

1、新建 dashboard模块

springcloud-consumer-hystrix-dashboard-9001 监控模块

1)导jar包

<!-- 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>

2)主启动类

@EnableHystrixDashboard 开启监控功能

@SpringBootApplication
@EnableHystrixDashboard
public class DepartmentConsumerDashboard_9001 {
    public static void main(String[] args) {
        SpringApplication.run(DepartmentConsumerDashboard_9001.class,args);
    }
}

3)配置yml

proxy-stream-allow-list: "*" 在新版本中需要配置这个

server:
  port: 9001

hystrix:
  dashboard:
    proxy-stream-allow-list: "*"

在这里插入图片描述

2、修改熔断服务提供者模块

被监控的方法需要有熔断功能

在这里插入图片描述

1)必备jar包

actuatorhystrix

<!-- 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>

2)主启动类

在主启动类中添加如下方法:

两个方法选一个就可以

@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: "*"

3、测试

启动

在这里插入图片描述

熔断服务提供者

在这里插入图片描述

在这里插入图片描述

监控页

在这里插入图片描述

在这里插入图片描述

4、总结

需要注意的几个点

  • 监控模块的yml中要配置 proxy-stream-allow-list: "*"
  • 被监控的方法要有 熔断服务
  • 监控页面填写流地址时用 主机名,不要用ip
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

土味儿~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值