preface
Spring Cloud was used in this paper as 2.1.8RELEASE, version=Greenwich.SR3
This article is based on the implementation of eureka-Server, Eureka-Client, Eureka-Ribbon and Eureka-Feign in the previous two articles. reference
- eureka-server
- eureka-client
- eureka-ribbon
- eureka-feign
concept
Hystrix Dashboard A control panel provided by Hystrix to view Hystrix monitoring data. Hystrix provides near real-time data monitoring. Hystrix records all HystrixCommand execution information in real time, including how many requests are executed per second, how many successes and failures.
Create the Hystrix Dashboard project
1.1 Creating a SPING Boot project: hysteric-Dashboard
1.2 Adding pom.xml dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
Copy the code
1.3 Application Adds configuration information
spring:
application:
name: hystrix-dashboard
server:
port: 8500
eureka:
instance:
hostname: localhost
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
client:
service-url:
defaultZone: http://eureka1.server.com:8701/eureka/,http://eureka2.server.com:8702/eureka/,http://eureka3.server.com:8703/eureka/
Copy the code
1.4 to start the class HystrixDashboardApplication add annotations
package spring.cloud.demo.hystrixdashboard;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@EnableHystrixDashboard
@EnableDiscoveryClient
@SpringBootApplication
public class HystrixDashboardApplication {
public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); }}Copy the code
EnableHystrixDashboard: Enable the HystrixDashboard circuit breaker kanban configuration
1.5 Starting the Hystrix-Dashboard service
Open a browser, type http://localhost:8500/hystrix shows the result is as follows:
Url input box: represents the service consumer to monitor
Single Hystrix App: https://hystrix-app:port/actuator/hystrix.stream: to monitor the path url format
1.6 Monitoring the Ribbon Service
1.6.1 Eureka-Ribbon Added Hystrix Configuration
package spring.cloud.demo.eurekaribbon.config;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/ * * *@auther: maomao
* @DateT: the 2019-09-17 * /
@Configuration
public class HystrixConfig {
@Bean
public ServletRegistrationBean getServlet(a) {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
returnregistrationBean; }}Copy the code
Start eureka-Client and Eureka-Ribbon services. Then enter the following in the URL box of the Hystrix Dashboard control panel:
Clicking Monitor Stream displays:
Unable to connect to Command Metric Stream Cause: Because we open the monitor circuit breaker flow Hystrix Stream path http://localhost:8901/hystrix.stream not spring boot the default path, also is not the default path Hystrix, All indicator flow servlets that want to add Hystrixconfig to specify circuit breakers.
Loading may also be displayed on the page after the first successful startup, which means that the service we want to monitor has not been accessed. In this way, we can see the indicator data when we request the service to be accessed for several times
In the same way I can set up the Eureka-Feign configuration for monitoring.
conclusion
This paper simply set up Hystrix Dashborad data monitoring platform.
Hystrix has stopped development and is in the maintenance stage. Hystrix has explained it on Github, suggesting us to use Resilience4J. The simplicity of Resilience4J will be updated later.
The code address
Making the address
- Eureka Server Service Registry tutorial for Spring Cloud 2.x
- Eureka Client Service Provider tutorial for Spring Cloud 2.x
- Spring Cloud 2.x Ribbon Service Discovery Tutorial (with Integrated Hystrix Fuse)
- Feign Service Discovery Tutorial with Integrated Hystrix Circuit breaker in Spring Cloud 2.x
- Spring Cloud 2.x Zuul Routing Gateway Tutorial
- Spring Cloud 2.x Config Distributed Configuration Center tutorial
- Spring Cloud 2.x Hystrix Dashboard Circuit breaker tutorial
Please indicate the source of reprint,
- Contact: [email protected]