SpringCloud study notes (5): Hystrix Dashboard visual monitoring data

Brief introduction

Last article talked about the use of fault-tolerant Hystrix addition, Hystrix also provides near real-time monitoring. This article describes how to use Hystrix Dashboard service monitoring and to make monitoring data graphically.

Project Introduction

  1. sc-parent, parent module (please refer SpringCloud Study Notes (1): Eureka registry )
  2. sc-eureka, Registration Center (refer to SpringCloud Study Notes (1): Eureka registry )
  3. sc-consumer-hystrix-ribbon, use Hystrix + Ribbon consumers (refer to SpringCloud study notes (4): Hystrix fault tolerance )
  4. sc-consumer-hystrix-feign, using Hystrix + Feign consumers (refer to SpringCloud study notes (4): Hystrix fault tolerance )
  5. sc-hystrix-dashboard, for visual monitoring data
  6. sc-turbine, monitoring data for the polymerization

Open consumer service monitoring

1. Modify the consumer sc-consumer-hystrix-ribbon and sc-consumer-hystrix-feign the pom.xml, add the following dependency:

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

2. Modify the consumer sc-consumer-hystrix-ribbon and sc-consumer-hystrix-feign the application.yml, add the following configuration:

management:
  endpoints:
    web:
      exposure:
        include: 'hystrix.stream'  #暴露hystrix.stream端点

3. Test Access consumers sc-consumer-hystrix-feign monitoring data

In turn starts registry sc-eureka and consumers sc-consumer-hystrix-feign, and visit http: // localhost: 8084 / actuator / hystrix.stream, results are shown below:

Appear on the map because the customer service is not being accessed, so here first call customer service at: http: // localhost: 8084 / feign / getBookList, and then visit http: // localhost: 8084 / actuator / hystrix.stream:

Monitoring data can be seen in the form of text display, not intuitive, the following will introduce the use Hystrix Dashboard visual monitoring data.

Using visual monitoring data Hystrix Dashboard

1. Create a sub-module project sc-hystrix-dashboard in the parent module, pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.cf</groupId>
    <artifactId>sc-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>sc-hystrix-dashboard</artifactId>
  
  <dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
    </dependency>
  </dependencies>
</project>

2. Create a startup class dashboard.DashBoardApplication:

package dashboard;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableHystrixDashboard
public class DashBoardApplication {
    public static void main(String[] args) {
        SpringApplication.run(DashBoardApplication.class, args);
    }
}

3. Create application.yml:

server:
  port: 8086

spring:
  application:
    name: sc-hystrix-dashboard

4. Test

After starting the sc-hystrix-dashboard, visit http: // localhost: 8086 / hystrix Hystrix Dashboard will display the main interface:

You then need to add data to monitor consumer sc-consumer-hystrix-feign to Hystrix Dashboard in. In turn starts registry sc-eureka and consumers sc-consumer-hystrix-feign, will address monitoring data input to Hystrix Dashboard main screen of the text box, click on the Monitor Stream, and then repeat visit Consumer Services http: // localhost: 8084 / feign / getBookList, Hystrix Dashboard shown below:

About content index represents the interface can refer to the following figure:

Turbine monitoring data using a polymerization

/hystrix.stream endpoint can monitor only a single service instance, if you want to see other examples of service monitoring information you need to address in Hystrix Dashboard switch you want to monitor. All /hystrix.stream data endpoint may be aggregated into a combined /turbine.stream by Turbine, then the monitoring information can view all the services in Hystrix Dashboard.

1. Modify the consumer sc-consumer-hystrix-ribbon and sc-consumer-hystrix-feign the application.yml, or directly set to true will registerWithEureka remove this configuration (the default is true). Because Turbine need to obtain address information from service Eureka, before you can get to the monitoring data services, so consumers need to Eureka registry service registration.

eureka:
  client:
    #registerWithEureka: false 
    serviceUrl:
      defaultZone: http://localhost:8080/eureka/  

2. Create a sub-module sc-turbine project in the parent module, pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.cf</groupId>
    <artifactId>sc-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>sc-turbine</artifactId>
  
  <dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
    </dependency>
  </dependencies>
</project>

3. Create a startup class turbine.TurbineApplication:

package turbine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@SpringBootApplication
@EnableTurbine
public class TurbineApplication {
    public static void main(String[] args) {
        SpringApplication.run(TurbineApplication.class, args);
    }
}

4. Create application.yml:

server:
  port: 8087

spring:
  application:
    name: sc-turbine
    
eureka:
  client:
    registerWithEureka: false
    serviceUrl:
      defaultZone: http://localhost:8080/eureka/    

turbine:
  appConfig: sc-consumer-hystrix-ribbon,sc-consumer-hystrix-feign #指定要监控的服务名
  clusterNameExpression: "'default'"

5. Test

In turn starts registry sc-eureka, consumers sc-consumer-hystrix-feign, consumers sc-consumer-hystrix-ribbon, sc-turbine, sc-hystrix-dashboard, visit http: // localhost: 8086 / hystrix into hystrix Dashboard main interface, and then enter the main interface in hystrix Dashboard text box http: // localhost: 8087 / turbine.stream, click monitor Stream into the control interface, repeat visits two consumer services, the interface will be displayed on two monitors a consumer of monitoring information:

Guess you like

Origin www.cnblogs.com/seve/p/11544065.html