这是一个从零开始的springcloud的系列教程,如果你从中间开始看,可能会看不明白.请进入我的系列教程开始从头开始学习.spring-cloud教程
Hytrix-Dashboard监控
在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。
沿用上节课创建eureka-client-feign工程,修改eureka-client-feign工程.
pom.xml
spring-cloud-learn
com.jack
1.0-SNAPSHOT
4.0.0
eureka-client-feign
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.cloud
spring-cloud-starter-openfeign
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-netflix-hystrix
org.springframework.cloud
spring-cloud-starter-netflix-hystrix-dashboard
org.springframework.boot
spring-boot-starter-actuator
修改EurekaClientFeignApplication
package com.jack.feign;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
// 启动feign的注解
@EnableFeignClients
// 启动dashboard
@EnableHystrixDashboard
// 启动hystrix
@EnableHystrix
public class EurekaClientFeignApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaClientFeignApplication.class, args );
}
}
application.yml需要加入以下配置,非常关键,因为数据是通过springboot的actuator来持续返回的,我们需要让actuator开放节点给我们,它默认开放health和info来个节点
# springboot的Actuator提供了运行状态监控的功能,可以通过REST、远程Shell和JMX方式来查看。
# 这个配置非常重要,否则会导致/actuator/hystrix.stream无法访问,hystrix.stream节点会持续提供熔断状态
management:
endpoints:
web:
# 2.0之前默认是/ 2.0默认是 /actuator
# base-path: /actuator
# 显示健康具体信息 默认不会显示详细信息
# management.endpoint.health.show-details=always
exposure:
# 默认开启health、info,可以通过/actuator/info访问,如果要暴露所有接口,填"*"
include: hystrix.stream
cors:
allowed-origins: "*"
allowed-methods: "*"
ok,启动服务,访问http://localhost:7773/actuator/hystrix.stream,会发现不断有数据返回,不过因为没有访问api,返回都是空
image.png
当我们访问http://localhost:7773/hello_store api (eureka-client服务没有启动)
此时服务就会出现数据
image.png
我们来打开图形界面控制面板,http://localhost:7773/hystrix
image.png
对着中间输入我们运行状态流服务节点http://localhost:7773/actuator/hystrix.stream
image.png
点击monitor stream.观察流.并且请求一次/hello_store服务.会发现出现一次错误.方法为FeignService#sayStore
image.png
这样我们就可以通过dashboard来观察熔断器的状态了.
但是这个远远是不够的,只能观察一台机器,并没有什么意义.接下来我们会介绍turbine.可以收集所有服务熔断器状态流