1. What is Dashboard
Hystrix-dashboard is a tool page for real-time monitoring of Hystrix. Through Hystrix Dashboard, we can intuitively see the request response time and request success rate of each Hystrix Command.
2. How to configure Dashboard - monitoring service
1. Import dependencies
<!--Hystrix依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<!--dashboard依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
2 configuration file configuration port number
server:
prot: 8899 # 端口号可以自行配置 只要是和别的服务的端口号不冲突就好
3. Start the service------Dashboard exists as an independent service
@SpringBootApplication
// 开启Dashboard
@EnableHystrixDashboard
public class DeptConsumerDashboard {
public static void main(String[] args) {
SpringApplication.run(DeptConsumerDashboard.class,args);
}
}
3. Monitored service configuration
1. Add monitoring information dependency
添加监控注解
<!--actuator 完善监控信息 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2. Add a servlet to the monitored service startup class
//增加一个Servlet
@Bean
public ServletRegistrationBean hystrixMetricsStreamServlet(){
ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
//参数固定写法
registrationBean.addUrlMappings("/actuator/hystrix.stream");
return registrationBean;
}
4. Monitoring effect diagram