微服务Hystrix Dashboard监控中心搭建
Hystrix Dashboard 是Hystrix熔断器的监控中心,搭建起来非常之方便,直接进入主题。
1.创建一个微服务专门用于监控服务的
引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
在启动类添加 @EnableHystrixDashboard 标注
@SpringBootApplication
@EnableHystrixDashboard
public class MonitorDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(MonitorDashboardApplication.class, args);
}
}
2.在你要监控熔断的微服务做以下操作
添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
在配置文件添加配置
#暴露actuator监控的所有端点
management:
endpoints:
web:
exposure:
include: '*'
3.访问测试
注意如果你的微服务继承了OAuth2.0框架,记得放行springboot下actuator下监控的接口,下面是例子。
@Override
public void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/actuator/**").permitAll()
.antMatchers("/**").authenticated()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
访问 http://localhost:8999/hystrix
在url填写地方填写 你要监控熔断的微服务的地址 例如http://localhost:8085/actuator/hystrix.stream ,点击Monitor Stream
4.但是微服务一多,要一个个输地址再去查看,非常麻烦,所以以下做法,可以输入一个url就监控多个微服务的熔断情况
在监控服务的微服务项目引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
在启动类标注@EnableTurbine
@SpringBootApplication
@EnableTurbine
@EnableHystrixDashboard
public class MonitorDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(MonitorDashboardApplication.class, args);
}
}
在配置文件中 ,把监控服务的微服务注册到注册中心中,还有turbine需要检测,那个微服务,要配置微服务名
server:
port: 8999
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8083/eureka/
spring:
application:
name: monitor-dashboard
turbine:
# 要监控的多个微服务列表 用英文逗号隔开
app-config: employeetwo
cluster-name-expression: "'default'"
完成测试,访问http://localhost:8999/hystrix监控微服务
在url填写框,填写http://localhost:8085/turbine.stream,点击Monitor Stream
这时候,你就可以看到,你在配置文件中配置的微服务的熔断信息类
一键查询淘宝/拼多多内部优惠券,每日大额外卖红包,购物省钱的宝藏工具