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

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;
}
发布了119 篇原创文章 · 获赞 9 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/getchar97/article/details/105097941