我是靠谱客的博主 害羞萝莉,这篇文章主要介绍九、Hystrix Dashboard,现在分享给大家,希望可以做个参考。

一、简介

Hystrix是由Netflix开源的一个延迟和容错库,实现熔断器。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是一个图形化界面,支持数据监控。

 

二、搭建熔断器服务

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>mo-cloud</artifactId> <groupId>com.mo</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <description>Hystrix Dashboard(断路器:Hystrix 仪表盘)只监控一个实例</description> <artifactId>hystrix-dashboard</artifactId> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 服务监控的依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <!-- 熔断依赖 --> <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> </dependencies> </project>
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
server: # springboot设置随机端口号 port: 0 eureka: client: service-url: default-zone: http://127.0.0.1:8761/eureka/ instance: # 重写服务的唯一Id,防止多实例对被注册成一个服务 instance-id: ${spring.application.name}:${random.int} # 设置优先使用ip进行注册 prefer-ip-address: true spring: application: name: hystrix-dashboard # actuator 安全检查开放消息推送刷新 management: endpoints: web: exposure: # 开放安全检查的端点 include: "*"
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.mo; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; import org.springframework.boot.SpringApplication; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; import org.springframework.context.annotation.Bean; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /** * EnableHystrixDashboard注解,开启HystrixDashboard,仪表盘监控服务 * SpringCloudApplication注解,支持服务注册,springboot启动,hystrix熔断 * * @author x.pan * @email px5215201314@163.com * @date 2020/5/2 16:23 */ @RestController @SpringCloudApplication @EnableHystrixDashboard public class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); } @GetMapping("/hello") @HystrixCommand(fallbackMethod = "helloError") public String hello() { return "hello"; } /** * HystrixCommand 熔断的失败返回方法 * * @return */ public String helloError() { return "hello error"; } /** * 版本差异:添加actuator端点hystrix.stream * <p> * 访问地址 http://localhost:xxx/actuator/hystrix.stream * * @return */ @Bean public ServletRegistrationBean hystrixMetricsStreamServlet() { ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet()); registration.addUrlMappings("/actuator/hystrix.stream"); return registration; } }

三、Hystrix Dashboard演示

1. 访问http://127.0.0.1:49859/hystrix

2. 添加 http://127.0.0.1:49859/actuator/hystrix.stream端点

3. 熔断监控,请求接口http://127.0.0.1:49859/hello 

 

 

 

最后

以上就是害羞萝莉最近收集整理的关于九、Hystrix Dashboard的全部内容,更多相关九、Hystrix内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(71)

评论列表共有 0 条评论

立即
投稿
返回
顶部