springcloud- 服务监控 hystrix dashboard

导入依赖

         <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就能够看到服务的详细状态

 

posted on   你就学个JVAV?  阅读(38)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示