SpringCloud入门(六): Hystrix监控(Dashboard/Turbian)

Hystrix.stream 监控



    org.springframework.boot
    spring-boot-starter-actuator



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界面简洁,但是显示不友好,不方便运维。

SpringCloud入门(六): Hystrix监控(Dashboard/Turbian)_第1张图片

Dashboard监控

 



    org.springframework.cloud
    spring-cloud-starter-netflix-hystrix-dashboard




@SpringBootApplication
@EnableHystrixDashboard
public class EurekaConsumerApplication {

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

 

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

 

 SpringCloud入门(六): Hystrix监控(Dashboard/Turbian)_第2张图片

 

集群监控Turbian



	org.springframework.cloud
	spring-cloud-starter-netflix-turbine



turbine.aggregator.cluster-config=default
turbine.app-config= ms-provider-order,ms-consumer-user
turbine.cluster-name-expression="'default'"
turbine.instanceUrlSuffix=hystrix.stream


turbine:
  aggregator:
    clusterConfig: default
  appConfig: ms-consumer-user
  cluster-name-expression: "'default'"
  instanceUrlSuffix: hystrix.stream


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

SpringCloud入门(六): Hystrix监控(Dashboard/Turbian)_第3张图片

 

 

 

 

你可能感兴趣的:(SpringCloud入门(六): Hystrix监控(Dashboard/Turbian))