zoukankan      html  css  js  c++  java
  • SpringCloud入门(六): Hystrix监控(Dashboard/Turbian)

    Hystrix.stream 监控

    <!--1. 配置pom文件,引入actuator包-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    
    
    <!- 2. 在Spring的启动入口添加@@EnableCircuitBreaker注解->
    @SpringBootApplication
    @EnableCircuitBreaker
    public class EurekaConsumerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaConsumerApplication.class, args);
        }
    }
    
    <!- 3. 引入HystrixMetricsStreamServlet->
    @Configuration
    public class HystrixConfig {
    
        @Bean
        public ServletRegistrationBean getStreamServlet(){
            HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
            ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
            registrationBean.setLoadOnStartup(1);  //系统启动时加载顺序
            registrationBean.addUrlMappings("/hystrix.stream");//路径
            registrationBean.setName("HystrixMetricsStreamServlet");
            return registrationBean;
        }
    }

    通过http://localhost:8006/hystrix.stream访问。hystrix.stream界面简洁,但是显示不友好,不方便运维。

    Dashboard监控

    <!--1. 配置pom文件,引入dashboard包-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
    </dependency>
    
    
    <!- 2. 在Spring的启动入口添加@EnableHystrixDashboard注解->
    @SpringBootApplication
    @EnableHystrixDashboard
    public class EurekaConsumerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaConsumerApplication.class, args);
        }
    }

    通过http://localhost:8006/hystrix访问。dashboard 只能监控单个服务,对运维人员依旧不友好,只能监控单工程,不能查看历史

     

    集群监控Turbian

    <!--1. 配置pom文件,引入dashboard包-->
    <dependency>
    	<groupId>org.springframework.cloud</groupId>
    	<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
    </dependency>
    
    <!- 2. 配置属性文件->
    turbine.aggregator.cluster-config=default
    turbine.app-config= ms-provider-order,ms-consumer-user
    turbine.cluster-name-expression="'default'"
    turbine.instanceUrlSuffix=hystrix.stream
    
    <!- 3. YML配置属性文件(只有yml生效,prop配置无效)->
    turbine:
      aggregator:
        clusterConfig: default
      appConfig: ms-consumer-user
      cluster-name-expression: "'default'"
      instanceUrlSuffix: hystrix.stream
    
    <!- 4. 在Spring的启动入口添加@EnableHystrixDashboard注解->
    @SpringBootApplication
    @EnableTurbine
    public class EurekaConsumerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(EurekaConsumerApplication.class, args);
        }
    }

    通过http://localhost:8006/turbine.stream访问。我们可以通过dashboard对turbine.stream进行监控

    备注:1)所有被监控的服务都需要配置Hystrix.stream监控,否则turbine识别不到。

        2)instanceUrlSuffix的默认值为:actuator/hystrix.stream;这个属性来自SpringClusterMonitor这个类。如果不配置这个属性会抛出一个MisconfiguredHostException的404异常。

        3)在为actuator包指定management.context-path=/xxx属性后也需要对instanceUrlSuffix做变更。

     

  • 相关阅读:
    Thinkphp3.2 cms之角色开发
    说几个你知道的设计模式?
    9种实现点击一个链接弹出一个小窗口的代码
    分享自己作为一个程序员的找工作经历
    网页设置锚点
    博客园网摘地址
    PHP面试总结
    简单的10秒倒计时
    PHP测试题目
    关键字搜索内容总结
  • 原文地址:https://www.cnblogs.com/jiangyaxiong1990/p/12398662.html
Copyright © 2011-2022 走看看