Hystrix:Dashboard流监控

1.创建springcloud--consumer-hystrixdashboard

1.1.在pom文件下添加以下内容:(导入依赖)

 <!--实体类web-->
    <dependencies>
        <dependency>
            <groupId>com.sxh</groupId>
            <artifactId>springcloid-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--热部署-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <!--Ribbon-->
        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-ribbon -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

        <!--导入eureka的客户端的依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>



        <!--Hystrix依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

    </dependencies>

1.2.创建yml文件,并写入端口号

server:
  port: 9001

1.3.创建主启动类,并添 加 @EnableHystrixDashboard 注解 已开启监控

2.修改springcloud-provider-dept-8001

2.1修改pom文件,添加以下依赖:

  <!--hystrix-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

2.2在主启动类添加以下内容:

 /*增加一个servlet*/
    @Bean
    public ServletRegistrationBean HystrixMetricsStreamServlet() {
        ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(new HystrixMetricsStreamServlet());
        registrationBean.addUrlMappings("/actuator/hystrix.stream");
        return registrationBean;
    }

测试:先启动springcloud-eureka-7001,再启动springcloud--consumer-hystrixdashboard,最后启动springcloud-provider-dept-8001

效果如下:

Last modification:February 6th, 2020 at 02:46 pm
如果觉得我的文章对你有用,请随意赞赏