1 新建工程 <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"> <modelVersion>4.0.0</modelVersion> <par
springcloud 中使用 hystrix-dashboard 进行监控的时候启动报错"path":"/actuator/hystrix.stream","status":404,"error":"
springcloud 中使用 hystrix-dashboard 进行监控的时候启动报错”path”:”/actuator/hystrix.stream”,”status”:404,”error”:”
在springcloud 体系中,可以用 hystrix-dashboard 实时监控服务的运行状态。上一文记录了单实例的监控,现在实现集群监控。 2. 2.7 pom.xml 重用 hystrix-dashboard 的依赖,另新增少量依赖: <?xml version="1.0" encoding="UTF-8"? description>监控面板-集群 </description> <parent> <groupId>com</groupId> <artifactId>hystrix-dashboard # 应用服务很多时,可用多个 hystrix-turbine 来监控不同的聚合集群,集群名可区分这些不同的聚合集群, # 此集群名亦可在 hystrix-dashboard 中用来定位不同的聚合集群: 此时,在 hystrix-dashboard 中使用集群监控的 URL 查看监控信息,在页面第一个输入框中输入 hystrix-turbine 工程的访问路径:http://localhost:8889
${REGPREFIX}/track:$(date -u "+%Y%m%d-%H%M%S") cd - #hystrix-dashboard progress "Building hystrix-dashboard hystrix-dashboard(5/${TOTAL}) docker image ..." docker tag $(docker build -t ${REGPREFIX}/hystrix-dashboard ${REGPREFIX}/track:$(date -u "+%Y%m%d-%H%M%S") cd - #hystrix-dashboard progress "Building hystrix-dashboard hystrix-dashboard(5/${TOTAL}) docker image ..." docker tag $(docker build -t ${REGPREFIX}/hystrix-dashboard hystrix-dashboard: container_name: hystrix-dashboard image: 127.0.0.1:5000/billjiang/hystrix-dashboard
创建一个hystrix-dashboard模块 用来监控hystrix实例的执行情况。 artifactId> </dependency> 在application.yml进行配置: server: port: 8501 spring: application: name: hystrix-dashboard HystrixDashboardApplication.class, args); } } 启动相关服务 这次我们需要启动如下服务:eureka-server、user-service、hystrix-service、hystrix-dashboard Hystrix 集群实例监控 这里我们使用Turbine来聚合hystrix-service服务的监控信息,然后我们的hystrix-dashboard服务就可以从Turbine获取聚合好的监控信息展示给我们了 User对象CRUD接口的服务 ├── hystrix-service -- hystrix服务调用测试服务 ├── turbine-service -- 聚合收集hystrix实例监控信息的服务 └── hystrix-dashboard
${REGPREFIX}/track:$(date -u "+%Y%m%d-%H%M%S") cd - #hystrix-dashboard progress "Building hystrix-dashboard (5/${TOTAL}) jar file ..." cd common/hystrix-dashboard mvn clean package -DskipTests progress "Building hystrix-dashboard(5/${TOTAL}) docker image ..." docker tag $(docker build -t ${REGPREFIX}/hystrix-dashboard ${REGPREFIX}/hystrix-dashboard:$(date -u "+%Y%m%d-%H%M%S") cd - #hystrix-turbine-mq progress "Buildinhg hystrix-dashboard: container_name: hystrix-dashboard image: 127.0.0.1:5000/billjiang/hystrix-dashboard
application.yml 中添加如下配置: management: endpoints: web: exposure: include: hystrix.stream 启用Hystrix-Dashboard 使用Hystrix一个最大的好处就是它会为我们自动收集每一个HystrixCommand的信息,并利用Hystrix-Dashboard通过一种高效的方式对每一个断路器的健康状态进行展示。 引入Hystrix-Dashboard依赖 在 pom.xml 文件中引入Hystrix-Dashboard依赖: <! MessageCenterApplication.class).web(WebApplicationType.SERVLET).run(args); } } 仪表盘界面 启动应用,访问 http://localhost:8781/hystrix ,打开Hystrix-Dashboard
application.yml,开放端口: management: endpoints: web: exposure: include: "*" 配置监控方 新建一个名为 hystrix-dashboard -- hystrix-dashboard --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId artifactId> </dependency> 新建 application.yml server: port: 9300 spring: application: name: Hystrix-Dashboard
Spring Boot 1.x 和 Spring Boot 2.x, 所以 0.2.0 即是和 Spring Boot 2.x 兼容的,0.1.0 则是和 Spring Boot 1.x 兼容的 2、 hystrix-dashboard xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.cntaiping.tpa</groupId> <artifactId>hystrix-dashboard </artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>hystrix-dashboard ; } } 2.5 运行效果 依次运行服务注册中心register-server模块和断路器监控hystrix-dashboard模块 ?
快速安装 Hystrix 控制面板为了更好地观察熔断器的实时状态,Hystrix 提供了一个控制面板 UI,可以使用 Docker 快速部署:# 拉取官方镜像docker pull mlabouardy/hystrix-dashboard :latest# 启动控制面板docker run -d -p 9002:9002 --name hystrix-dashboard mlabouardy/hystrix-dashboard:latest
新建一个 springboot 工程 hystrix-dashboard,实现 hystrix 的监控面板。( 工程详细新建方式在前面几篇博客中均有说明 ) 1.1 工程结构: ? maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com</groupId> <artifactId>hystrix-dashboard </artifactId> <version>0.0.1-SNAPSHOT</version> <name>hystrix-dashboard</name> <description>服务监控-面板 build> </project> 1.3 application.properties : # 端口 server.port= 8888 # 工程名 spring.application.name= hystrix-dashboard
显然,一堆密密麻麻的文字,没有人会喜欢看,spring-cloud早就想到这一点了,提供了一个hystrix-dashboard的功能,可以用图形化的界面来解读这些数据。 再起一个项目,名为hystrix-dashboard,build.gradle参考下面: buildscript { repositories { maven { HystrixDashboardApplication.class, args); } } 当然,这也是一个微服务,也可以注册到eureka上,参考下面的配置: spring: application: name: hystrix-dashboard
Spring Cloud中创建一个Hystrix Dashboard非常简单,如下: 第一步:创建一个普通的Spring Boot工程 创建一个Spring Boot工程这个比较简单,直接创建一个名为hystrix-dashboard } } 第四步:属性配置 最后,我们可以根据个人偏好来配置一下application.properties文件,我这里配置两个基本的属性,如下: spring.application.name=hystrix-dashboard 这样会使本地调试有问题 查看监控图 OK,监控服务创建成功之后,我们再次依次启动eureka-server、provider和consumer,其中consumer启动两个实例,两个实例的端口不一致,再分别启动hystrix-dashboard
我们构建的内容包括: eureka-server:服务注册中心 eureka-client:服务提供者 eureka-consumer-ribbon-hystrix:使用ribbon和hystrix实现的服务消费者 hystrix-dashboard 分别启动eureka-server、eureka-client、eureka-consumer-ribbon-hystrix、turbine以及hystrix-dashboard。
HystrixDashboardStream的实现就是按一定的时间间隔固定的去轮询所有自己存储的指标,用户可以选择自己感兴趣的数据做持久化 它实际上就是单机版的 hystrix-dashboard( hystrix自带的带图形化的架空) 的实现原理,只是无法做持久化,只能看实时的结果,感兴趣的同学可以先启动hystrix-dashboard 查看结果,然后再启动这个web服务,启动后按照web服务项目的
查看应用暴露的监控端点 我们可以从IDEA的Run Dashboard中查看到所有暴露的Actuator监控端点,这里以hystrix-dashboard(断路器仪表盘服务)为例。 ?
Hystrix Dashboard Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command
网页,你会看到良好的图形化界面: 源码下载: https://github.com/forezp/SpringCloudLearning/tree/master/chapter12 五、参考资料 hystrix-dashboard
lookup parent from repository --> </parent> <groupId>com.codesofun</groupId> <artifactId>hystrix-dashboard </artifactId> <version>0.0.1-SNAPSHOT</version> <name>hystrix-dashboard</name> <description plugins> </build> </project> application.properties中添加配置 server.port=8081 spring.application.name=hystrix-dashboard