4.1 Spring Cloud微服务入门之HystrixDashboard监控搭建

  1. 新建cloud-consumer-hystrix-dashboard9001

  2. 改POM

            
            <dependency>
                <groupId>org.springframework.cloudgroupId>
                <artifactId>spring-cloud-starter-netflix-hystrix-dashboardartifactId>
            dependency>
    
    
  3. 改YML 给定一个端口号
    在这里插入图片描述

  4. 主启动加@EnableHystrixDashboard 开启监控功能

  5. 所有Provider微服务提供类(8001,8002)都需要加监控依赖配置

    • 开启@EnableCircuitBreaker 熔断注解是必须的

    • 升级spring cloud H 版后有个bug 需要在被监控微服务主启动类下做如下配置

      /*
           * 此配置是为了服务监控配置,
           * */
          @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;
          }
      
  6. 启动
    4.1 Spring Cloud微服务入门之HystrixDashboard监控搭建_第1张图片
    4.1 Spring Cloud微服务入门之HystrixDashboard监控搭建_第2张图片### 案例地址:gitee:https://gitee.com/albertchen521/cloud2020

你可能感兴趣的:(Spring,Cloud)