Spring Cloud构建微服务架构Hystrix监控面板

本文详细介绍如何在Spring Cloud环境中快速构建HystrixDashboard,包括创建项目、配置依赖、启用监控等功能。并介绍了如何为服务实例添加/hystrix.stream接口以实现监控。

在Spring Cloud中构建一个Hystrix Dashboard非常简单,只需要下面四步:

  • 创建一个标准的Spring Boot工程,命名为:hystrix-dashboard。
  • 编辑pom.xml,具体依赖内容如下:
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
     
<parent>
<groupId>org.springframework.cloud </groupId>
<artifactId>spring-cloud-starter-parent </artifactId>
<version>Dalston.SR1 </version>
<relativePath />
</parent>
<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>
  • 为应用主类加上@EnableHystrixDashboard,启用Hystrix Dashboard功能。
     
1
2
3
4
5
6
7
     
@EnableHystrixDashboard
@SpringCloudApplication
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
  • 根据实际情况修改application.properties配置文件,比如:选择一个未被占用的端口等,此步非必须。
     
1
2
     
spring.application.name=hystrix-dashboard
server.port=1301

既然Hystrix Dashboard监控单实例节点需要通过访问实例的/hystrix.stream接口来实现,自然我们需要为服务实例添加这个端点,而添加该功能的步骤也同样简单,只需要下面两步:

  • 在服务实例pom.xml中的dependencies节点中新增spring-boot-starter-actuator监控模块以开启监控相关的端点,并确保已经引入断路器的依赖spring-cloud-starter-hystrix
     
1
2
3
4
5
6
7
8
     
<dependency>
<groupId>org.springframework.cloud </groupId>
<artifactId>spring-cloud-starter-hystrix </artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot </groupId>
<artifactId>spring-boot-starter-actuator </artifactId>
</dependency>
  • 确保在服务实例的主类中已经使用@EnableCircuitBreaker@EnableHystrix注解,开启了断路器功能。

到这里已经完成了所有的配置,已启动对“eureka-consumer-ribbon-hystrix”的监控,点击“Monitor Stream”按钮。


从现在开始,我这边会将近期研发的springcloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,希望可以帮助更多的好学者。大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。源码来源

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值