springcloud- 服务监控 hystrix dashboard

发布时间 2023-07-07 15:37:07作者: 你就学个JVAV?

导入依赖

         <dependency>
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
 </dependency>

编写yml配置

 server:
   port: 9001    

加上核心注解

 @SpringBootApplication
 @EnableHystrixDashboard // 核心注解
 public class DashBoardMain9001 {
     public static void main(String[] args) {
         SpringApplication.run(DashBoardMain9001.class,args);
     }
 }

在服务端8001启动类中加上一个bean,是springcloud新版的一个坑

     /**
      *此配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑
      *ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",
      *只要在自己的项目里配置上下面的servlet就可以了
      */
     @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;
     }

输入要监控的服务:http://localhost:8001/hystrix.stream
输入监控的面板地址:http://localhost:9001/hystrix就能够看到服务的详细状态