Hystrix Dashboard监控面板

骑猪看日落 2022-05-16 00:48 278阅读 0赞

Hystrix Dashboard监控面板

概述

本篇博文引入Hystrix Dashboard实现对微服务的实时监控及界面化监控。

实现步骤分析

引入相关依赖依赖

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.cloud</groupId>
  4. <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
  5. </dependency>
  6. </dependencies>

创建application.yml文件

  1. spring:
  2. application:
  3. name: hystrix-dashboard
  4. server:
  5. port: 9100

创建springcloud-hystrix-dashboard启动类

  1. import org.springframework.boot.SpringApplication;
  2. import org.springframework.boot.autoconfigure.SpringBootApplication;
  3. import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
  4. @EnableHystrixDashboard // 启动hystrix监控面板
  5. @SpringBootApplication
  6. public class Application {
  7. public static void main(String[] args) throws Exception {
  8. SpringApplication.run(Application.class, args);
  9. }
  10. }

此时,启动项目,并在浏览器里访问http://localhost:9100/hystrix/即可进入Hystrix Dashboard监控首页面,如下图所示:
这里写图片描述

监控首页面根据不同的架构模式提供了有一种监控方式:

  1. Cluster via Turbine (default cluster): http://turbine-hostname:port/turbine.stream(这是针对Turbine集群(默认集群))
  2. Cluster via Turbine (custom cluster): http://turbine-hostname:port/turbine.stream?cluster=clusterName
  3. Single Hystrix App: http://hystrix-app:port/hystrix.stream(单体应用模式)

以上仅实现了Hystrix Dashboard监控系统搭建,下面介绍如何实现对服务的监控

Hystrix Dashboard服务监控

Single Hystrix App单体应用模式

要实现服务的监控,需要修改被监控服务的配置及依赖,本例以springcloud-service-consumer-feign-hystrix这个工程为服务消费端介绍如何实现监控。

修改消费端pom依赖,引入Hystrix Dashboard依赖

需要增加以下依赖:

  1. <dependency>
  2. <groupId>org.springframework.cloud</groupId>
  3. <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-actuator</artifactId>
  8. </dependency>

启动熔断机制

在主启动类上增加@EnableCircuitBreaker
修改后的启动类如下:

  1. @SpringBootApplication
  2. @EnableFeignClients // 启动Feign
  3. @EnableCircuitBreaker // 启动熔断机制
  4. public class Application {
  5. public static void main(String[] args) throws Exception {
  6. SpringApplication.run(Application.class, args);
  7. }
  8. }

测试

分别启动springcloud-hystrix-dashboardspringcloud-service-consumer-feign-hystrix这两个工程,在浏览器里多次访问http://localhost:9000/consumer/request/info,并通过http://localhost:9100/hystrix/monitor?stream=http://localhost:9000/hystrix.stream即可查看监控的详细信息,如下图:
这里写图片描述

Cluster via Turbine (default cluster) | Cluster via Turbine (custom cluster)

后续补齐

源代码链接:
https://github.com/myNameIssls/springcloud-study/tree/master/springcloud-hystrix-dashboard

参考链接:
http://cloud.spring.io/spring-cloud-static/Finchley.SR1/multi/multi__circuit_breaker_hystrix_dashboard.html
http://cloud.spring.io/spring-cloud-static/Finchley.SR1/multi/multi__hystrix_timeouts_and_ribbon_clients.html
https://blog.csdn.net/yejingtao703/article/details/77683102
https://www.cnblogs.com/chenweida/p/9025589.html

发表评论

表情:
评论列表 (有 0 条评论,278人围观)

还没有评论,来说两句吧...

相关阅读