第九节 Dubbo中使用仪表盘

亮子 2021-08-31 20:39:39 17399 0 0 0

1、增加依赖

        <!--熔断仪表盘-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>

2、启动类增加注解

package com.shenmazong.serveruserconsumer;

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

@SpringBootApplication
@EnableHystrix
@EnableHystrixDashboard
public class ServerUserConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServerUserConsumerApplication.class, args);
    }
}

3、创建Servlet配置

SpringBoot2.x版本开启Hystrix Dashboard需要增加一个HystrixMetricssStreamServlet的配置,代码如下:

package com.shenmazong.serveruserconsumer.config;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HystrixDashboardConfiguration {

    @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean();

        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        registrationBean.setServlet(streamServlet);

        return registrationBean;
    }
}
  • 首页

图片alt

  • 监控

图片alt