博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据
阅读量:4610 次
发布时间:2019-06-09

本文共 4242 字,大约阅读时间需要 14 分钟。

简介

上篇文章中讲了使用Hystrix实现容错,除此之外,Hystrix还提供了近乎实时的监控。本文将介绍如何进行服务监控以及使用Hystrix Dashboard来让监控数据图形化。

项目介绍

  1. sc-parent,父模块(请参照)
  2. sc-eureka,注册中心(请参照)
  3. sc-consumer-hystrix-ribbon,使用Hystrix+Ribbon的消费者(请参照)
  4. sc-consumer-hystrix-feign,使用Hystrix+Feign的消费者(请参照)
  5. sc-hystrix-dashboard,用于可视化监控数据
  6. sc-turbine,用于聚合监控数据

开启消费者服务监控

1.修改消费者sc-consumer-hystrix-ribbon和sc-consumer-hystrix-feign的pom.xml,新增如下依赖:

org.springframework.boot
spring-boot-starter-actuator

2.修改消费者sc-consumer-hystrix-ribbon和sc-consumer-hystrix-feign的application.yml,新增如下配置:

management:  endpoints:    web:      exposure:        include: 'hystrix.stream'  #暴露hystrix.stream端点

3.测试访问消费者sc-consumer-hystrix-feign的监控数据

依次启动注册中心sc-eureka和消费者sc-consumer-hystrix-feign,并访问http://localhost:8084/actuator/hystrix.stream,结果显示如下:

945558-20190918174933119-936279277.jpg

出现上图是因为消费者服务没有被访问,所以这里先调用下消费者服务:http://localhost:8084/feign/getBookList,然后再访问http://localhost:8084/actuator/hystrix.stream:

945558-20190918174939684-1299584707.jpg

可以看到监控数据是以文字的形式展示的,并不直观,下面将介绍使用Hystrix Dashboard可视化监控数据。

使用Hystrix Dashboard可视化监控数据

1.在父模块下创建子模块项目sc-hystrix-dashboard,pom.xml:

4.0.0
com.cf
sc-parent
0.0.1-SNAPSHOT
sc-hystrix-dashboard
org.springframework.cloud
spring-cloud-starter-netflix-hystrix-dashboard

2.创建启动类dashboard.DashBoardApplication:

package dashboard;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;@SpringBootApplication@EnableHystrixDashboardpublic class DashBoardApplication {    public static void main(String[] args) {        SpringApplication.run(DashBoardApplication.class, args);    }}

3.创建application.yml:

server:  port: 8086spring:  application:    name: sc-hystrix-dashboard

4.测试

启动sc-hystrix-dashboard后,访问http://localhost:8086/hystrix将会显示Hystrix Dashboard的主界面:

945558-20190918174950499-1676887412.jpg

然后需要将消费者sc-consumer-hystrix-feign的监控数据添加到Hystrix Dashboard中。依次启动注册中心sc-eureka和消费者sc-consumer-hystrix-feign,将监控数据的地址输入到Hystrix Dashboard主界面的文本框中,点击Monitor Stream,然后重复访问消费者服务http://localhost:8084/feign/getBookList,Hystrix Dashboard显示如下:

945558-20190918175003677-806920645.jpg

关于界面上指标表示的内容可以参考下图:

945558-20190918175010078-1300927956.jpg

使用Turbine聚合监控数据

/hystrix.stream端点只能监控到单个服务实例,如果需要查看其他服务实例监控信息则需要在Hystrix Dashboard切换想要监控的地址。通过Turbine可以将所有/hystrix.stream端点的数据聚合到一个组合的/turbine.stream中,然后在Hystrix Dashboard中就可以查看所有服务的监控信息。

1.修改消费者sc-consumer-hystrix-ribbon和sc-consumer-hystrix-feign的application.yml,将registerWithEureka设为true或者直接去掉该配置(默认为true)。因为Turbine需要从Eureka上获取服务的地址信息,然后才能获取到服务的监控数据,所以消费者服务需要到Eureka注册中心注册。

eureka:  client:    #registerWithEureka: false     serviceUrl:      defaultZone: http://localhost:8080/eureka/

2.在父模块下创建子模块项目sc-turbine,pom.xml:

4.0.0
com.cf
sc-parent
0.0.1-SNAPSHOT
sc-turbine
org.springframework.cloud
spring-cloud-starter-netflix-turbine

3.创建启动类turbine.TurbineApplication:

package turbine;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.turbine.EnableTurbine;@SpringBootApplication@EnableTurbinepublic class TurbineApplication {    public static void main(String[] args) {        SpringApplication.run(TurbineApplication.class, args);    }}

4.创建application.yml:

server:  port: 8087spring:  application:    name: sc-turbine    eureka:  client:    registerWithEureka: false    serviceUrl:      defaultZone: http://localhost:8080/eureka/    turbine:  appConfig: sc-consumer-hystrix-ribbon,sc-consumer-hystrix-feign #指定要监控的服务名  clusterNameExpression: "'default'"

5.测试

依次启动注册中心sc-eureka、消费者sc-consumer-hystrix-feign、消费者sc-consumer-hystrix-ribbon、sc-turbine、sc-hystrix-dashboard,访问http://localhost:8086/hystrix进入到Hystrix Dashboard主界面中,然后在Hystrix Dashboard主界面的文本框中输入http://localhost:8087/turbine.stream,点击Monitor Stream进入监控界面,重复访问两个消费者服务,监控界面上将显示两个消费者的监控信息:

945558-20190918175020005-1741151877.jpg

转载于:https://www.cnblogs.com/seve/p/11544065.html

你可能感兴趣的文章
3、流程语句相关练习
查看>>
30、git 使用
查看>>
iOS网络-02-数据解析(JSON与XML)
查看>>
python列表求和的几种等效电路
查看>>
Luogu P3393 逃离僵尸岛
查看>>
Flatten Binary Tree to Linked List
查看>>
Edit Distance
查看>>
软件工程第一次作业补充
查看>>
N76E003---输入捕获
查看>>
poj 1094 Sorting It All Out(拓扑排序)
查看>>
acdream B - 郭式树 (水题 卡cin,cout, 卡LL)
查看>>
BMP图像格式
查看>>
python的匿名函数lambda解释及用法
查看>>
c#遍历Dictionary使用KeyValuePair
查看>>
defineProperties属性的运用==数据绑定
查看>>
关于 IOS 发布的点点滴滴记录(一)
查看>>
《EMCAScript6入门》读书笔记——14.Promise对象
查看>>
CSS——水平/垂直居中
查看>>
Eclipse连接mysql数据库jdbc下载(图文)
查看>>
Python中Selenium的使用方法
查看>>