SpringCloud_Hystrix_Dashboard流监控

一.导入依赖

1.创建Dashboard模块并导入依赖

        <!--Hystrix熔断依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            <version>2.2.10.RELEASE</version>
        </dependency>
        <!--Dashboard依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            <version>2.2.10.RELEASE</version>
        </dependency>

2.为被监控的服务提供端导入依赖

        <!--actuator监控信息依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.6.7</version>
        </dependency>
        <!--Dashboard依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            <version>2.2.10.RELEASE</version>
        </dependency>
        <!--Hystrix熔断依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            <version>2.2.10.RELEASE</version>
        </dependency>

二.代码部分

1.编写Dashboard模块主启动类

注:为主启动类添加@EnableHystrixDashboard注解以开启Dashboard监控页面

@SpringBootApplication
@EnableHystrixDashboard//开启Dashboard监控页面
public class DeptConsumerDashboard_9001 {
    public static void main(String[] args) {
        SpringApplication.run(DeptConsumerDashboard_9001.class);
    }
}

2.为服务提供端主启动类添加bean

    //配置收集流数据的servlet
    //访问 http://localhost:8001/actuator/hystrix.stream
    @Bean
    public ServletRegistrationBean SRB(){
        ServletRegistrationBean servletRB = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
//        servletRB.setName("HystrixMetricsStreamServlet");//名字
//        servletRB.setLoadOnStartup(1);//启动优先级
        servletRB.addUrlMappings("/actuator/hystrix.stream");
        return servletRB;
    }

三.配置yml文件

配置Dashboard模块的yml文件 

server:
  port: 9001

hystrix:
  dashboard:
    proxy-stream-allow-list: "localhost" #允许Dashboard监控的流的ip地址

运行效果

访问http://localhost:9001/hystrix

在该页面访问http://localhost:8001/actuator/hystrix.stream

注:需要先访问一次启用了熔断机制的服务,否则将一直loading,无法获取数据

进行多次错误请求,可以看到此时熔断机制已经开启

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值