The meaning of the data in the Hystrix dashboard

Hystrix dashboard, just like the car's dashboard that displays various data of the car in real time, the Hystrix dashboard is mainly used to monitor the real-time running status of Hystrix, through which we can see the information of various indicators of Hystrix, so as to quickly discover the system. The existing problem and then solve it, OK, in this article, we will take a look at how to use the Hystrix dashboard.

This article is the fifteenth article in the Spring Cloud series. Understanding the content of the first fourteen articles will help you better understand this article:

1. Use Spring Cloud to build a service registry 
2. Use Spring Cloud to build a high-availability service registry 
3. Service discovery and consumption in Spring Cloud 
4. Core concepts in Eureka 
5. What is client load balancing 
6. In Spring RestTemplate 
Several common request ways _  _ _ _ _ _ Spring Cloud custom Hystrix request command 12. Service degradation and exception handling of Hystrix in Spring Cloud 13. Request cache of Hystrix in Spring Cloud 14. Request merge of Hystrix in Spring Cloud
 
 
 
 
 
 

In this article, we will look at the use of Hystrix dashboards from two aspects, one is to monitor single applications, and the other is to integrate Turbine to monitor clusters. The case in this article is formed on the basis of the previous article, so the construction process of the entire environment will not be repeated here.

Monitor Monolithic Applications

Monitoring environment construction

Whether it is monitoring a single application or Turbine cluster monitoring, we all need a Hystrix Dashboard. Of course, we can continue to add functions to the single application to be monitored, so that it also has the function of a dashboard, but this is not in line with our microservices Therefore, I still create a new project for Hystrix Dashboard separately for Hystrix Dashboard. OK, creating a Hystrix Dashboard in Spring Cloud is very simple, as follows:

Step 1: Create a normal Spring Boot project

Creating a Spring Boot project is relatively simple, just create a Spring Boot project named hystrix-dashboard.

Step 2: Add related dependencies

After the Spring Boot project is created, modify the pom.xml file and add related dependencies, as follows:

<parent>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-parent</artifactId>
    <version>Dalston.SR3</version>
    <relativePath/> 
</parent>
<dependencies>
    <!-- 其他默认依赖 -->
    <!-- 我们需要添加的依赖 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
</dependencies>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

Dependency Here, we mainly modify the content of parent, and then add three dependencies, be careful not to miss any omissions.

Step 3: Add annotations to the entry class

After adding the dependencies, add the @EnableHystrixDashboard annotation to the entry class, indicating that the dashboard function is enabled, as follows:

@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardApplication.class, args);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

Step 4: Property Configuration

Finally, we can configure the application.properties file according to our personal preferences. I configure two basic properties here, as follows:

spring.application.name=hystrix-dashboard
server.port=2001
  • 1
  • 2

OK, after doing this, our monitoring environment is basically set up successfully.

running result

After the environment is successfully built, run the Spring Boot project, we can see the following page:

write picture description here

I have marked the meaning of the three parameters in the figure.

OK, now our dashboard project has been created successfully, but it cannot be used to monitor a certain service. To monitor a certain service, the service needs to provide a /hystrix.stream interface, so, we need to monitor our service consumers The project has been slightly modified.

Retrofit the service to be monitored

Let's transform our service consumer project. The transformation method is very simple. It can be done in two steps. First, add the following dependencies to the pom.xml file:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

Then add the @EnableCircuitBreaker annotation to the entry class of the service consumer project, indicating that the circuit breaker function is enabled. At this point, let's start our eureka-server, provider, and consumer projects again. In the startup log of the consumer project, we can see the following information:

write picture description here

This information indicates that our consumer project currently has the /hystrix.stream interface, and we can directly access this interface. But here is a detail that needs to be paid attention to: to access the /hystrix.stream interface, you must first access any other interface in the consumer project, otherwise if you directly access the /hystrix.stream interface, a series of pings will be printed: ping : ….  OK, I first access any other interface in the consumer, and then access the /hystrix.stream interface, the access address is as follows: http://localhost:9000/hystrix.stream , the access results are as follows:

write picture description here

We see that the returned result is a piece of json data. It is difficult for us to analyze the result by simply viewing the json data. Therefore, we need to view this piece of json in the Hystrix dashboard, and enter the monitoring address in the hystrix dashboard, as follows:

write picture description here

Then click the Monitor Stream button, we can see the monitoring screen, as follows: 
write picture description here

Detailed parameter explanation

OK, the dashboard has been displayed, so what do the various data on the dashboard mean? Let's look at the following picture:

write picture description here

Turbine cluster monitoring

OK, we saw an example of monitoring a single application above. In practical applications, the application we want to monitor is often a cluster. At this time, we have to use Turbine cluster monitoring. An important function of Turbine is to aggregate monitoring information and provide the aggregated monitoring information to Hystrix Dashboard for centralized display and monitoring. Then let's take a look at how Turbine cluster monitoring is used.

Build a monitoring environment

The construction of the monitoring environment is also divided into four steps:

Step 1: Create a normal Spring Boot project

The first step is to create a normal Spring Boot project called turbine.

Step 2: Add dependencies

After the project is created, we need to add a dependency, as follows:

<parent>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-parent</artifactId>
    <version>Dalston.SR3</version>
    <relativePath/> 
</parent>
<dependencies>
    <!-- 其他默认的依赖 -->
    <!-- 我们要添加的依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-turbine</artifactId>
    </dependency>
</dependencies>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

Step 3: Add annotations

Add the @EnableTurbine annotation to the entry class to enable Turbine, as follows:

@SpringBootApplication
@EnableDiscoveryClient
@EnableTurbine
public class TurbineApplication {

    public static void main(String[] args) {
        SpringApplication.run(TurbineApplication.class, args);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

Step 4: Modify the configuration

Add the relevant configuration of eureka and turbine to the application.properties configuration file, as follows:

spring.application.name=turbine
server.port=2002
management.port=2003
eureka.client.service-url.defaultZone=http://localhost:1111/eureka/
turbine.app-config=ribbon-consumer
turbine.cluster-name-expression="default"
turbine.combine-host-port=true
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Regarding this configuration file, I say the following:

1.turbine.app-config=ribbon-consumer specifies that the name of the application to be monitored is ribbon-consumer 
2.turbine.cluster-name-expression=”default”, indicating that the name of the cluster is default 
3.turbine.combine-host- port=true means that services on the same host are distinguished by the combination of host and port. By default, host is used to distinguish, which will make local debugging problematic

View monitoring graph

OK, after the monitoring service is successfully created, we start eureka-server, provider and consumer again in turn. The consumer starts two instances, and the ports of the two instances are inconsistent. Then start hystrix-dashboard and turbine respectively, and then enter in the hystrix monitoring address bar. The following address ( remember to visit any interface in the service before monitoring ): http://localhost:2002/turbine.stream , the access results are as follows:

write picture description here

As you can see, the display of the host report column under the cluster is different.

OK, we will introduce the Hystrix dashboard and Turbine cluster monitoring in Spring Cloud. If you have any questions, please leave a message for discussion.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325231720&siteId=291194637