我是靠谱客的博主 鲜艳老鼠,这篇文章主要介绍【SpringCloud深入浅出系列】SpringCloud组件之集成Hystrix Dashboard一、Hystrix Dashboard 是什么?二、创建项目实现 Hystrix Dashboard,现在分享给大家,希望可以做个参考。

SpringCloud 组件之集成 Hystrix Dashboard

  • 一、Hystrix Dashboard 是什么?
  • 二、创建项目实现 Hystrix Dashboard
    • 1.添加依赖
    • 2.添加配置
    • 3.启动类加入注解
    • 4.启动类注入 ServletRegistrationBean
    • 5.启动服务


一、Hystrix Dashboard 是什么?

Hystrix 仪表盘主要用来监控 Hystrix 的实时运行状态,通过它我们可以看到 Hystrix 的各项指标信息,从而快速发现系统中存在的问题进而解决它。

二、创建项目实现 Hystrix Dashboard

1.添加依赖

pom.xml 文件中加入依赖 spring-boot-starter-actuator 和 spring-cloud-starter-netflix-hystrix-dashboard,spring-boot-starter-actuator 为服务监控依赖:

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

2.添加配置

application.yml 文件中添加配置用来暴露 endpoints,由于 endpoints 中会包含很多敏感信息,除了 health 和 info 两个支持直接访问外,其他的默认不能直接访问,所以进行指定:

复制代码
1
2
3
4
5
6
management: endpoints: web: exposure: include: hystrix.stream

3.启动类加入注解

在启动类中加入注解 @EnableHystrixDashboard,开启Hystrix Dashboard:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.chaoyue.consumer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication @EnableEurekaClient @EnableFeignClients @EnableHystrixDashboard public class ConsumerApplication { public static void main(String[] args) { SpringApplication.run(ConsumerApplication.class, args); } }

4.启动类注入 ServletRegistrationBean

在启动类注入 ServletRegistrationBean,该 Bean 的作用是在 Hystrix Dashboard 中打开 hystrix.stream:

复制代码
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
package com.chaoyue.consumer; import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; @SpringBootApplication @EnableEurekaClient @EnableFeignClients @EnableHystrixDashboard public class ConsumerApplication { public static void main(String[] args) { SpringApplication.run(ConsumerApplication.class, args); } @Bean public ServletRegistrationBean getServlet(){ HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet); registrationBean.setLoadOnStartup(1); registrationBean.addUrlMappings("/hystrix.stream"); registrationBean.setName("HystrixMetricsStreamServlet"); return registrationBean; } }

5.启动服务

启动服务。浏览器输入:http://localhost:8082/hystrix
在这里插入图片描述
监控 Stream 输入:http://localhost:8082/hystrix.stream,点击【Monitor Stream】
在这里插入图片描述

最后

以上就是鲜艳老鼠最近收集整理的关于【SpringCloud深入浅出系列】SpringCloud组件之集成Hystrix Dashboard一、Hystrix Dashboard 是什么?二、创建项目实现 Hystrix Dashboard的全部内容,更多相关【SpringCloud深入浅出系列】SpringCloud组件之集成Hystrix内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部