其他分享
首页 > 其他分享> > SpringCloud入门(六): Hystrix监控

SpringCloud入门(六): Hystrix监控

作者:互联网

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做变更。

 

 

 

 

 

 

 

 

<!--1. 配置pom文件,引入dashboard包--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-turbine</artifactId></dependency>
<!- 2. 配置属性文件->turbine:  aggregator:    clusterConfig: default  appConfig: ms-consumer-ribbon-user,ms-consumer-feign-user  cluster-name-expression: "'default'"
<!- 3. 在Spring的启动入口添加@EnableHystrixDashboard注解->@SpringBootApplication@EnableTurbinepublic class EurekaConsumerApplication {
    public static void main(String[] args) {        SpringApplication.run(EurekaConsumerApplication.class, args);    }}

标签:入门,stream,SpringCloud,args,class,EurekaConsumerApplication,turbine,public,Hystri
来源: https://www.cnblogs.com/jiangyaxiong1990/p/12398662.html