springcloud----服务熔断、降级、限流--之--Hystrix-监控中心

本文介绍如何使用Spring Cloud Netflix Hystrix Dashboard构建服务监控仪表盘,包括配置pom.xml依赖、设置yml参数、编写主启动类,并通过ServletRegistrationBean注册Hystrix Metrics Stream Servlet,实现对指定服务的实时监控。

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

Netflix相关文档 : https://cloud.spring.io/spring-cloud-static/spring-cloud-netflix/2.2.2.RELEASE/reference/html/

1、模块名 cloud-consumer-hystrix-dashboard9001
2、pml.xml
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>
3、yml 配置文件
server:
  port: 9001
4、主启动
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashBoardMain9001 {
    public static void main(String[] args){
        SpringApplication.run(HystrixDashBoardMain9001.class,args) ;
    }
}
5、测试
  • 监控中心地址: http://127.0.0.1:9001/hystrix
  • 指定监控的地址 : http://127.0.0.1:8001/hystrix.stream
  • 访问后才能参数流量

在需要监控的启动类 增加Bean

/**
 *  此配置是为了服务监控而配置,与服务容错本省无关,spring-cloud 升级后的坑
 *  ServletRegistrationBean 因为 spring boot 的默认路径不是 "/hystrix.stream"
 *  只要在自己的项目里配置下文的 servlet 就可以了
 * @return
 */
@Bean
public ServletRegistrationBean getServlet() {
    HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
    registrationBean.setLoadOnStartup(1);
    registrationBean.addUrlMappings("/hystrix.stream");
    registrationBean.setName("HystrixMetricsStreamServlet");
    return registrationBean;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值