〖Spring Cloud〗Dashboard 流监控

121 阅读1分钟

Dashboard 流监控

相关视频参考www.bilibili.com/video/BV1nK…

相关资料下载:www.bjpowernode.com/?juejin  

新建springcloud-consumer-hystrix-dashboard模块

添加依赖

<!--Hystrix依赖-->

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-hystrix</artifactId>

    <version>1.4.6.RELEASE</version>

</dependency>

<!--dashboard依赖-->

<dependency>

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>

    <version>1.4.6.RELEASE</version>

</dependency>

<!--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>

<!--实体类+web-->

<dependency>

    <groupId>com.haust</groupId>

    <artifactId>springcloud-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>

 

主启动类

@SpringBootApplication

// 开启Dashboard

@EnableHystrixDashboard

public class DeptConsumerDashboard_9001 {

    public static void main(String[] args) {

        SpringApplication.run(DeptConsumerDashboard_9001.class,args);

    }

}

给springcloud-provider-dept-hystrix-8001模块下的主启动类添加如下代码,添加监控

@SpringBootApplication

@EnableEurekaClient //EnableEurekaClient 客户端的启动类,在服务启动后自动向注册中心注册服务

public class DeptProvider_8001 {

    public static void main(String[] args) {

        SpringApplication.run(DeptProvider_8001.class,args);

    }

 

    //增加一个 Servlet

    @Bean

    public ServletRegistrationBean hystrixMetricsStreamServlet(){

        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());

        //访问该页面就是监控页面

        registrationBean.addUrlMappings("/actuator/hystrix.stream");

       

        return registrationBean;

    }

}

访问:http://localhost:9001/hystrix

image.png

进入监控页面:

image.png

效果如下图:  

image.png