Hystrix Dashboard
Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix
Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。
Hystrix Dashboard模块代码实现
- POM
<!--hystrix dashboard-->
<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-dashboard</artifactId>
</dependency>
- yaml
server:
port: 9001
- 主启动加
@EnableHystrixDashboard
注解
@SpringBootApplication
@EnableHystrixDashboard
public class DashBoardMain {
public static void main(String[] args) {
SpringApplication.run(DashBoardMain.class,args);
}
}
- 启动访问http://localhost:9001/hystrix/出现以下页面即成功
- 在需要监控的主启动类指定监控路径
@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
//注册Servlet
ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(streamServlet);
//值越小,该servlet的优先级越高
registrationBean.setLoadOnStartup(1);
//指定UrlMapping
registrationBean.addUrlMappings("/hystrix.stream");
//指定name,如果不指定默认为dispatcherServlet
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
- 输入url地址点击下方按钮即可进入监控页面
服务监控页面
- 监控说明