Spring Cloud(07)——Hystrix Dashboard

Hystrix Dashboard

Spring Cloud Spring Boot Specification-based monitoring also provides indicators to monitor Hystrix information. To see these monitoring information, you first need to add the following dependence in pom.xml.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Endpoint ID Hystrix Spring Cloud monitoring information is provided hystrix.stream, in order to see the corresponding monitoring information, also need to Hystrix corresponding endpoint to http way to release it. The following can be expressly specified needs to be published hystrix.stream.

management.endpoints.web.exposure.include=hystrix.stream

All endpoint can be directly specified publication.

management.endpoints.web.exposure.include=*

Released hystrix.streamlater, as with other endpoint, through /actuator/endpointIdinformation corresponding to the acquired endpoint released, it can /actuator/hystrix.streamaccess to monitoring information Hystrix released, then you can see something like this below.

hystrix.stream

You may also see is always displayed on the screen ping:, this is because the application has just started, not to @HystrixCommandinitiate a request tagging method, but also no corresponding information.

hystrix.streamJSON format is directly visible data are not intuitive. Hystrix a corresponding graphical monitoring interface, Spring Cloud also achieve the integration thereof. Graphical control interface need to add the following dependency in pom.xml.

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

Then add in the configuration class @EnableHystrixDashboardto enable support for the dashboard.

@SpringBootApplication
@EnableHystrixDashboard
@EnableCircuitBreaker
public class Application {

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

}

After through /hystrixaccess to home monitoring interface, you'll see the following interface.

Hystrix Dashboard

As shown in FIG red marker portion, the address of the stand-alone to collect monitoring information is accessible http://hystrix-app:port/actuator/hystrix.streamformat, the author of the application deployment in 8900 port of the machine, the address monitoring information is collected by the author http://localhost:8900/actuator/hystrix.stream, it is filled into a first input box then click the button Monitor Streamto start monitoring, you will see a screen like interface.

Hystrix Dashboard Monitor

In this page you can see each monitoring @HystrixCommandthe state of the corresponding circuit breaker, time-consuming, the failure rate, and the status of the corresponding thread pool for each request.

 

turbine

hystrix.stream只能看到单个应用的监控信息。通常同一个服务会部署多份,使用hystrix.stream查看每个单个应用的情况会比较麻烦,也不利于分析。Netflix提供了一个可以聚合多个应用的监控信息的工具,叫turbine。使用turbine时,一般会独立一个工程,在pom.xml中添加如下依赖。

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

turbine在聚合多个应用实例的监控信息是通过Eureka进行实例发现的,所以它本身将作为一个Eureka Client,还需要往pom.xml中添加Eureka Client的依赖。

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

使用turbine的工程的配置类上需要加上@EnableHystrixDashboard启用Hystrix Dashboard,加上@EnableTurbine启用turbine支持。而此时被聚合的应用可以不再启用Hystrix Dashboard。

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class Application {

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

}

使用turbine还需要进行一些配置,如下配置指定了Eureka Server的地址,且当前应用不需要向Eureka Server进行注册。turbine.appConfig指定了需要聚合的应用,对应于向Eureka Server注册的serviceId,即spring.application.name指定的值,下面的配置指定的需要聚合的服务是spring1。turbine.aggregator.clusterConfig指定了集群的名称,集群的名称只是用来把turbine.appConfig配置的服务名称分个组,默认是服务名称的大写形式,所以我们这里配置为SPRING1。

eureka.client.serviceUrl.defaultZone=http://localhost:8089/eureka/
eureka.client.registerWithEureka=false
server.port=9000

turbine.appConfig=spring1
turbine.aggregator.clusterConfig=SPRING1

turbine.appConfigturbine.aggregator.clusterConfig需要指定成一样的。

服务启动后,就可以通过/turbine.stream?cluster=SPRING1访问到类似如下这样收集到的群集SPRING1的信息。

turbine stream

hystrix.stream一样,上面收集到的信息是JSON格式,不直观。我们也可以在Hystrix Dashboard中查看对应的图形界面信息。通过访问/hystrix进入Hystrix Dashboard的首页,在输入监控地址的位置输入http://localhost:9000/turbine.stream?cluster=SPRING1,然后点击Monitor Stream按钮进入监控页面,你会看到类似如下这样的界面。

turbine stream dashboard

turbine也可以同时监控多个不同的服务,监控多个不同的服务时,多个不同的服务之间以英文的逗号分隔,集群名称之间也是以英文逗号分隔。比如下面的配置,可以通过集群SPRING1监控服务spring1的相关信息,通过集群SPRING2监控服务spring2的相关信息。

turbine.appConfig=spring1,spring2
turbine.aggregator.clusterConfig=SPRING1,SPRING2

When a turbine at the same time specify multiple cluster information, you can /clustersbetter see the definition of cluster information. Access based on the above configuration information http://localhost:9000/clusterssee the following information.

cluster info

When the cluster name using the default, you can not specify access turbine.stream cluster. The following configuration can be specified cluster name for the default. The following configuration is equivalent to specifying the service spring1 and spring2 cluster names are default, when the monitor can monitor information about these two services simultaneously.

turbine.appConfig=spring1,spring2
turbine.clusterNameExpression="default"

If it is on YAML configuration, you specify turbine.clusterNameExpressiona value "'default'".

(Note: This article is written based on Spring cloud Finchley.SR1)

Guess you like

Origin www.iteye.com/blog/elim-2443924