SpringCloud:Dashboard流监控

郎家岭伯爵 2022年06月25日 364次浏览

背景

前面我们实现了Hystrix服务熔断和服务降级,本文我们将继续介绍Dashboard流监控

实现

consumer-hystrix-dashboard

创建springcloud-consumer-hystrix-dashboard模块。

创建模块

编译pom.xml

<dependencies>

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

        <dependency>
            <groupId>com.langjialing</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.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>com.netflix.ribbon</groupId>
            <artifactId>ribbon-loadbalancer</artifactId>
            <version>2.2.5</version>
        </dependency>


</dependencies>

编辑application.yaml

server:
  port: 9001

创建启动类

package com.langjialing.springcloud;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableHystrixDashboard //开启Dashboard监控
public class DeptConsumerDashboard_9001 {
    public static void main(String[]  args){
        SpringApplication.run(DeptConsumerDashboard_9001.class, args);
    }
}

注:

  • 服务提供者必须要有spring-boot-starter-actuator依赖,否则Dashboard无法监控到服务情况。

功能测试一

访问localhost:9001/hystrix,进入Dashboard监控页面:

consumer-dept-hystrix-8001

修改springcloud-consumer-dept-hystrix-8001模块。

修改主启动类

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

启动服务提供者

启动springcloud-consumer-dept-hystrix-8001模块。

功能测试二

注:

  • 这里本应该是一个如下的监控页面,但博主的页面一直处于Loading状态。这里应该是版本的问题,与实际操作无关。这里作为一个存疑之处,后续有时间再来解决。

总结

本文我们实现了HystrixDashboard流监控,后续我们将继续完成SpringCloud的最后一个点:路由网关

赞助页面示例