Hystrix Dashboard for Real-time Monitoring
Hystrix Dashboard provieds real-time visualization of Hystrix command metrics including response times and success rates. While useful for single applications, it requires Turbine to aggregate data from multiple services.
Settting Up Hystrix Dashboard
Add the required dependencies to your Maven configuration:
<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-actuator</artifactId>
</dependency>
Configuration and Servlet Setup
Enable Hystrix Dashboard and Circuit Breaker in your main application class:
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ServiceConsumerApp {
public static void main(String[] args) {
SpringApplication.run(ServiceConsumerApp.class, args);
}
@Bean
public ServletRegistrationBean<HystrixMetricsStreamServlet> metricsServlet() {
HystrixMetricsStreamServlet servlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean<HystrixMetricsStreamServlet> registration =
new ServletRegistrationBean<>(servlet, "/hystrix.stream");
registration.setLoadOnStartup(1);
registration.setName("HystrixMetricsServlet");
return registration;
}
}
Access the dashboard at http://localhost:9001/hystrix and monitor the stream endpoint to view metrics.
Turbine for Cluster Monitoring
Turbine aggregates Hystrix streams from multiple service instances into a single data source for dashboard visuailzation.
Turbine Dependencies
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine-stream</artifactId>
</dependency>
Configuration Properties
spring.application.name=hystrix-turbine-dashboard
server.port=8002
turbine.app-config=service-consumer-a,service-consumer-b
turbine.aggregator.cluster-config=default
turbine.cluster-name-expression=new String("default")
eureka.client.service-url.default-zone=http://localhost:8088/eureka/
turbine.instance-url-suffix.default=hystrix.stream
Turbine Application Setup
@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
@EnableTurbineStream
public class TurbineMonitorApp {
public static void main(String[] args) {
SpringApplication.run(TurbineMonitorApp.class, args);
}
}
After starting all services, access http://localhost:8002/hystrix and monitor the turbine stream to view aggregated metrics from multiple service instances.