如何使用SpringCloud-Hystrix-dashboard进行监控?

本文指导如何在Spring Boot应用中集成Hystrix Dashboard,通过添加依赖、配置端口和监控,实现实时监控服务健康状态。从新建模块到设置监控URL,详细步骤助你轻松搭建监控界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先需要新建一个module

只需要添加一个依赖

        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix-dashboard -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            <version>2.2.9.RELEASE</version>
        </dependency>

@EnableHystrixDashboard在启动类上加此注解
请添加图片描述
在yaml中配置端口号和监控
请添加图片描述
然后在服务提供者中添加依赖

        <!-- 熔断 https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix -->
        <!--Dashboard监控一定要导入并开启-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            <version>2.2.9.RELEASE</version>
        </dependency>
         <!-- 监控-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

在启动类中将监控需要的bean注入进去
请添加图片描述

    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet(){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        //访问该页面就是监控页面
        registrationBean.addUrlMappings("/actuator/hystrix.stream");

        return registrationBean;
    }

需要监控的方法上面都要加上这个注解,不然是监控不了
请添加图片描述
访问监控的网址,然后输入需要监控的服务提供者
请添加图片描述

进入就可以监控到访问

请添加图片描述
直接访问这个网址,可以看到所有访问数据
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值