0
点赞
收藏
分享

微信扫一扫

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

自由情感小屋 2022-02-15 阅读 138

1、新建 dashboard模块

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)主启动类

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

3)配置yml

server:
  port: 9001

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

在这里插入图片描述

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

在这里插入图片描述

1)必备jar包

<!-- 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;
    }*/
# 监控端口配置
management:
  endpoints:
    web:
      exposure:
        # 开启 info,health;新版本中只默认开启了 health
        include: info,health
        # 
        #include: "*"

3、测试

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

4、总结

  • 监控模块的yml中要配置 proxy-stream-allow-list: "*"
  • 被监控的方法要有 熔断服务
  • 监控页面填写流地址时用 主机名,不要用ip
举报

相关推荐

0 条评论