一 介绍
Hystrix DashBoard监控单实例节点需要访问实例的/hystrix.stream接口来实现。
二 项目架构
项目的实现部分见红色框起来的部分。
三 实战步骤
1 在服务实例的pom.xml中增加相关依赖项目,主要是下面两项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
2 在项目的启动类上加上注解@EnableCircuitBreaker,开启断路器功能
package com.didispace;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@EnableCircuitBreaker
@EnableDiscoveryClient
@SpringBootApplication
public class ConsumerApplication {
@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
}
3 启动项目
4 在Hystrix Dashboard的首页输入:http://localhost:9000/hystrix.stream,可以看到已启动实例的监控。
四 hystrix-Dashboard面板说明
1 页面中的Delay
该参数用来控制服务器上轮询监控信息的延迟时间,默认为2000毫秒,可通过配置该属性来降低客户端的网络和CPU消耗。
2 页面中Title
该参数对应了头部标题Hystrix Stream之后的内容,默认会使用具体监控实例的URL。
3 实心圆
通过颜色的变化反映实例的健康程序,它的健康度从绿色、黄色、橙色、红色递减。通过大小反映了请求流量的变化,流量越大,实心圆越大。
4 曲线
用来记录2分钟内容流量的相对变化,通过它来观察流量上升和下降的趋势。
5 其他指标
见图例的说明。