一 Hystrix仪表盘介绍
度量指标都是HystrixCommand和HystrixObservableCommand实例在执行过程中记录的重要信息,它们除了在Hystrix断路器实现中使用之外,对于系统运维的帮助也很大。
度量指标会以“滚动时间窗”与“桶”结合的方式进行汇总,并在内存中驻留一段时间,以供内部或外部查询使用,Hystrix仪表盘就是这些指标内容的消费者之一。
二 项目实战介绍
构建一个Hystrix Dashboard项目。
三 项目架构图
本篇要实现的部分是用红色框起来的部分
四 实战步骤
1 创建一个标准的Spring boot项目,命名为hystrix-dashboard
2 编辑pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
3 在应用主类上加入注解@EnableHystrixDashboard,用来启动Hystrix Dashboard功能
package com.didispace;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@EnableHystrixDashboard
@SpringCloudApplication
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
4 修改配置文件
spring.application.name=hystrix-dashboard
server.port=2001
5 测试
启动该应用,并访问http://localhost:2001/hystrix
6 说明
这是Hystrix Dashboard的监控首页,它共支持三种不同的监控方式
- 默认的集群监控:http://turbine-hostname:port/turbine.stream
- 指定的集群监控:http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
- 单体应用的监控:http://hystrix-app:port/hystrix.stream
前两种是对集群的监控,需要整合Turbine,第三种是对单个服务实例的监控。