spring-cloud-starter-netflix-eureka-client
org.springframework.cloud
spring-cloud-starter-netflix-hystrix-dashboard
org.springframework.boot
spring-boot-starter-actuator
在application.yml进行配置:
server:
port: 8501
spring:
application:
name: hystrix-dashboard
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8001/eureka/
在启动类上添加@EnableHystrixDashboard来启用监控功能:
@EnableHystrixDashboard
@EnableDiscoveryClient
@SpringBootApplication
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
启动相关服务
这次我们需要启动如下服务:eureka-server、user-service、hystrix-service、hystrix-dashboard,启动后注册中心显示如下。
Hystrix实例监控演示
访问Hystrix Dashboard:http://localhost:8501/hystrix
填写好信息后点击监控按钮,这里我们需要注意的是,由于我们本地不支持https,所以我们的地址需要填入的是http,否则会无法获取监控信息;
还有一点值得注意的是,被监控的hystrix-service服务需要开启Actuator的hystrix.stream端点,配置信息如下:
management:
endpoints:
web:
exposure:
#暴露hystrix监控端点
include: ‘hystrix.stream’
调用几次hystrix-service的接口:http://localhost:8401/user/testCommand/1
可以发现曾经我们在@HystrixCommand中添加的commandKey和threadPoolKey属性都显示在上面了,并且有4次调用都成功了。
Hystrix Dashboard 图表解读
图表解读如下,需要注意的是,小球代表该实例健康状态及流量情况,颜色越显眼,表示实例越不健康,小球越大,表示实例流量越大。曲线表示Hystrix实例的实时流量变化。
这里我们使用Turbine来聚合hystrix-service服务的监控信息,然后我们的hystrix-dashboard服务就可以从Turbine获取聚合好的监控信息展示给我们了。
创建一个turbine-service模块
用来聚合hystrix-service的监控信息。
在pom.xml中添加相关依赖:
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.cloud
spring-cloud-starter-netflix-turbine
在application.yml进行配置,主要是添加了Turbine相关配置:
server:
port: 8601
spring:
application:
name: turbine-service
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8001/eureka/
turbine:
指定需要收集信息的服务名称
app-config: hystrix-service
指定服务所属集群
cluster-name-expression: new String(‘default’)
以主机名和端口号区分服务
combine-host-port: true
在启动类上添加@EnableTurbine来启用Turbine相关功能:
@EnableTurbine
@EnableDiscoveryClient
@SpringBootApplication
public class TurbineServiceApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineServiceApplication.class, args);
}
}
知其然不知其所以然,大厂常问面试技术如何复习?
1、热门面试题及答案大全
面试前做足功夫,让你面试成功率提升一截,这里一份热门350道一线互联网常问面试题及答案助你拿offer
2、多线程、高并发、缓存入门到实战项目pdf书籍
3、文中提到面试题答案整理
4、Java核心知识面试宝典
覆盖了JVM 、JAVA集合、JAVA多线程并发、JAVA基础、Spring原理、微服务、Netty与RPC、网络、日志、Zookeeper、Kafka、RabbitMQ、Hbase、MongoDB 、Cassandra、设计模式、负载均衡、数据库、一致性算法 、JAVA算法、数据结构、算法、分布式缓存、Hadoop、Spark、Storm的大量技术点且讲解的非常深入
bitMQ、Hbase、MongoDB 、Cassandra、设计模式、负载均衡、数据库、一致性算法 、JAVA算法、数据结构、算法、分布式缓存、Hadoop、Spark、Storm的大量技术点且讲解的非常深入**
[外链图片转存中…(img-bUEygTjS-1714455063210)]
[外链图片转存中…(img-B7abgobi-1714455063211)]
[外链图片转存中…(img-UthFsFUc-1714455063211)]