前言
本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3
概念
Hystrix Dashboard时Hystrix提供的一个可以查看hystrix监控数据的控制面板。Hystrix提供了近实时的数据监控,Hystrix会实时、累加的记录所有关于HystrixCommand的执行信息,包括每秒执行多少请求,多少成功和多少失败等。
创建Hystrix Dashboard工程
1.1 创建sping boot工程:hysteric-dashboard
1.2 添加pom.xml相关依赖
<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>
1.3 application添加配置信息
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/
1.4 启动类HystrixDashboardApplication增加注解
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);
}
}
1.5 启动hystrix-dashboard服务
打开浏览器,输入http://localhost:8500/hystrix显示结果如下:
1.6 监控ribbon服务
1.6.1 eureka-ribbon增加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: 2019-09-17
*/
@Configuration
public class HystrixConfig {
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}
启动eureka-client和eureka-ribbon服务。然后在hystrix dashboard控制面板url框中输入:
点击Monitor Stream会显示:
按照同样的方式我可以设置eureka-feign的配置来进行监看。
总结
代码地址
- spring cloud 2.x版本 Eureka Server服务注册中心教程
- spring cloud 2.x版本 Eureka Client服务提供者教程
- spring cloud 2.x版本 Ribbon服务发现教程(内含集成Hystrix熔断机制)
- spring cloud 2.x版本 Feign服务发现教程(内含集成Hystrix熔断机制)
- spring cloud 2.x版本 Zuul路由网关教程
- spring cloud 2.x版本 config分布式配置中心教程
- spring cloud 2.x版本 Hystrix Dashboard断路器教程
- 联系方式:[email protected]