Foreword
In Spring Cloud Advanced Road | Six: circuit breakers (Hystrix) article, describes the service fuse and circuit breaker assembly downgrade. However, these data after all see and touch, not monitoring.
So, you need a monitor capable of components for circuit breakers, Hystrix Dashboard breaker monitoring component that is to be introduced in this article, the component data for each of the circuit breaker, provide a friendly graphical interface.
Ready to work
Multiplexing Spring Cloud Advanced Road | Six: circuit breakers (Hystrix) all construction in the article: xmall-product, xmall-product -clients-ribbon, xmall-product-clients-feign.
ribbon way to monitor breaker
Transformation xmall-product-clients-ribbon project, add its dependencies and configuration.
Dependent transformation
Add dependent spring-boot-starter-actuator, spring-cloud-starter-netflix-hystrix-dashboard. pom file modified as follows.
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.luas.cloud</groupId>
<artifactId>java-boot-parent-2.1</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../java-boot-parent-2.1</relativePath>
</parent>
<groupId>com.luas.xmall</groupId>
<artifactId>xmall-product-clients-ribbon</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>xmall-product-clients-ribbon</name>
<description>product service clients by ribbon</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- nacos cloud -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Note: Be sure to add a spring-boot-starter-actuator-dependent, or will not create /actuator/hystrix.stream endpoint.
Turn the breaker monitoring
Add @EnableHystrixDashboard startup class notes, open the circuit breaker monitoring component.
package com.luas.xmall.product.clients;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@EnableHystrix
@EnableHystrixDashboard
@SpringBootApplication
public class XmallProductClientsRibbonApplication {
public static void main(String[] args) {
SpringApplication.run(XmallProductClientsRibbonApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
monitor
Start project xmall-product, xmall-product-clients-ribbon, ports are 8080,8082.
As configured correctly, the console will print /actuator/hystrix.stream successful endpoint registration information.
Visit http: // localhost: 8082 / actuator / hystrix.stream, if configured correctly, there will be a series of ping.
Visit http: // localhost: 8082 / hystrix, enter the relevant parameters are as follows:
Click Monitor Stream, to open the circuit breaker monitoring interface.
Can be seen, appear two monitors are loading. Do not panic, because there is no data.
Visit http: // localhost: 8082 / sku / 1122, appeared normal product information.
At this point, then observe hystrix.stream, there have been relevant data.
hystrix monitoring interface has been properly display graphical interface.
The console also displays information on a successful connection.
feign way breaker monitoring
Dependent transformation
Add dependent spring-boot-starter-actuator, spring-cloud-starter-netflix-hystrix-dashboard. pom file modified as follows.
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.luas.cloud</groupId>
<artifactId>java-boot-parent-2.1</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../java-boot-parent-2.1</relativePath>
</parent>
<groupId>com.luas.xmall</groupId>
<artifactId>xmall-product-clients-feign</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>xmall-product-clients-feign</name>
<description>product service clients by ribbon</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- nacos cloud -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Note: Be sure to add a spring-boot-starter-actuator-dependent, or will not create /actuator/hystrix.stream endpoint.
Turn the breaker monitoring
Start class add annotations @EnableCircuitBreaker , @ EnableHystrixDashboard.
package com.luas.xmall.product.clients;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableCircuitBreaker
@EnableHystrixDashboard
@EnableFeignClients("com.luas.xmall.product.clients.clients")
@SpringBootApplication
public class XmallProductClientsFeignApplication {
public static void main(String[] args) {
SpringApplication.run(XmallProductClientsFeignApplication.class, args);
}
}
Note: Although feign integrated hystrix, can be configured manually open the breaker, however, want to open the circuit breaker associated monitoring function, you need to add @EnableCircuitBreaker comment.
monitor
Start project xmall-product, xmall-product-clients-feign, ports are 8080,8083.
As configured correctly, the console will print /actuator/hystrix.stream successful endpoint registration information.
Visit http: // localhost: 8083 / actuator / hystrix.stream, if configured correctly, ping a series of still occur.
访问http://localhost:8083/hystrix,将监控地址变更为http://localhost:8083/actuator/hystrix.stream,点击Monitor Stream,开启新的断路器监控界面。
可以看到,依然是两处监控均出现loading,还是因为没有数据。
访问http://localhost:8083/sku/1122,正常出现商品信息。然后,再观察hystrix.stream,也已经出现了相关数据。
此时,hystrix监控界面已正常展示图形化界面。
控制台也显示了连接成功信息。
到此,断路器监控组件集成完成。
监控指标
断路器监控指标含义如下图所示。
此图是基于ribbon方式的断路器监控,feign方式的与此一模一样,唯一不同的,就是短路点名称格式。ribbon方式直接为方法名,而feign方式既有服务名,又有参数类型,比较详细。
源码
github
https://github.com/liuminglei/SpringCloudLearning/tree/master/11/
gitee
https://gitee.com/xbd521/SpringCloudLearning/tree/master/11/
本文系【银河架构师】原创,如需转载请在文章明显处注明作者及出处。
微信搜索【银河架构师】,发现更多精彩内容。