SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据
简介
上篇文章中讲了使用Hystrix实现容错,除此之外,Hystrix还提供了近乎实时的监控。本文将介绍如何进行服务监控以及使用Hystrix Dashboard来让监控数据图形化。
项目介绍
- sc-parent,父模块(请参照SpringCloud学习笔记(1):Eureka注册中心)
- sc-eureka,注册中心(请参照SpringCloud学习笔记(1):Eureka注册中心)
- sc-consumer-hystrix-ribbon,使用Hystrix+Ribbon的消费者(请参照SpringCloud学习笔记(4):Hystrix容错机制)
- sc-consumer-hystrix-feign,使用Hystrix+Feign的消费者(请参照SpringCloud学习笔记(4):Hystrix容错机制)
- sc-hystrix-dashboard,用于可视化监控数据
- sc-turbine,用于聚合监控数据
开启消费者服务监控
1.修改消费者sc-consumer-hystrix-ribbon和sc-consumer-hystrix-feign的pom.xml,新增如下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
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,结果显示如下:
出现上图是因为消费者服务没有被访问,所以这里先调用下消费者服务:http://localhost:8084/feign/getBookList,然后再访问http://localhost:8084/actuator/hystrix.stream:
可以看到监控数据是以文字的形式展示的,并不直观,下面将介绍使用Hystrix Dashboard可视化监控数据。
使用Hystrix Dashboard可视化监控数据
1.在父模块下创建子模块项目sc-hystrix-dashboard,pom.xml:
<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>
<parent>
<groupId>com.cf</groupId>
<artifactId>sc-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>sc-hystrix-dashboard</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
</dependencies>
</project>
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
@EnableHystrixDashboard
public class DashBoardApplication {
public static void main(String[] args) {
SpringApplication.run(DashBoardApplication.class, args);
}
}
3.创建application.yml:
server:
port: 8086
spring:
application:
name: sc-hystrix-dashboard
4.测试
启动sc-hystrix-dashboard后,访问http://localhost:8086/hystrix将会显示Hystrix Dashboard的主界面:
然后需要将消费者sc-consumer-hystrix-feign的监控数据添加到Hystrix Dashboard中。依次启动注册中心sc-eureka和消费者sc-consumer-hystrix-feign,将监控数据的地址输入到Hystrix Dashboard主界面的文本框中,点击Monitor Stream,然后重复访问消费者服务http://localhost:8084/feign/getBookList,Hystrix Dashboard显示如下:
关于界面上指标表示的内容可以参考下图:
使用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:
<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>
<parent>
<groupId>com.cf</groupId>
<artifactId>sc-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>sc-turbine</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
</dependencies>
</project>
3.创建启动类turbine.TurbineApplication:
package turbine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
@SpringBootApplication
@EnableTurbine
public class TurbineApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}
4.创建application.yml:
server:
port: 8087
spring:
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进入监控界面,重复访问两个消费者服务,监控界面上将显示两个消费者的监控信息:
SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据的更多相关文章
- SpringCloud学习笔记(3)——Hystrix
参考Spring Cloud官方文档第13.14.15章 13. Circuit Breaker: Hystrix Clients Netflix提供了一个叫Hystrix的类库,它实现了断路器模式. ...
- SpringCloud学习笔记(4):Hystrix容错机制
简介 在微服务架构中,微服务之间的依赖关系错综复杂,难免的某些服务会出现故障,导致服务调用方出现远程调度的线程阻塞.在高负载的场景下,如果不做任何处理,可能会引起级联故障,导致服务调用方的资源耗尽甚至 ...
- SpringCloud学习笔记(3):使用Feign实现声明式服务调用
简介 Feign是一个声明式的Web Service客户端,它简化了Web服务客户端的编写操作,相对于Ribbon+RestTemplate的方式,开发者只需通过简单的接口和注解来调用HTTP API ...
- SpringCloud学习笔记(6):使用Zuul构建服务网关
简介 Zuul是Netflix提供的一个开源的API网关服务器,SpringCloud对Zuul进行了整合和增强.服务网关Zuul聚合了所有微服务接口,并统一对外暴露,外部客户端只需与服务网关交互即可 ...
- timeout超时时长优化和hystrix dashboard可视化分布式系统
在生产环境中部署一个短路器,一开始需要将一些关键配置设置的大一些,比如timeout超时时长,线程池大小,或信号量容量 然后逐渐优化这些配置,直到在一个生产系统中运作良好 (1)一开始先不要设置tim ...
- SpringCloud学习笔记:服务支撑组件
SpringCloud学习笔记:服务支撑组件 服务支撑组件 在微服务的演进过程中,为了最大化利用微服务的优势,保障系统的高可用性,需要通过一些服务支撑组件来协助服务间有效的协作.各个服务支撑组件的原理 ...
- GIS案例学习笔记-三维生成和可视化表达
GIS案例学习笔记-三维生成和可视化表达 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:针对栅格或者矢量数值型数据,进行三维可视化表达 操作时间:15分钟 案 ...
- SpringCloud学习笔记(2):使用Ribbon负载均衡
简介 Spring Cloud Ribbon是基于Netflix Ribbon实现的一套客户端负载均衡工具,在注册中心对Ribbon客户端进行注册后,Ribbon可以基于某种负载均衡算法,如轮询(默认 ...
- SpringCloud学习笔记(7):使用Spring Cloud Config配置中心
简介 Spring Cloud Config为分布式系统中的外部化配置提供了服务器端和客户端支持,服务器端统一管理所有配置文件,客户端在启动时从服务端获取配置信息.服务器端有多种配置方式,如将配置文件 ...
随机推荐
- Fabric项目学习总结
1.Hyperledger Fabric的基本架构 2.PKI机制
- c#自定义控件中的事件处理
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; u ...
- 实战SpringCloud响应式微服务系列教程(第三章)
接着之前的: 实战SpringCloud响应式微服务系列教程(第一章) 实战SpringCloud响应式微服务系列教程(第二章) 1.1.3Reactor框架 响应式编程是一种编程模型,本节将介绍这种 ...
- Google Protocol Buffer Basics: C++
proto文件简介 每个元素上的"= 1","= 2"标记标识该字段在二进制编码中使用的唯一"标记" 每个字段有三个可选修饰符 requir ...
- k好数(动态规划)
问题描述 如果一个自然数N的K进制表示中任意的相邻的两位都不是相邻的数字,那么我们就说这个数是K好数.求L位K进制数中K好数的数目.例如K = 4,L = 2的时候,所有K好数为11.13.20.22 ...
- Docker学习总结(六)--Dockerfile
什么是 Dockerfile Dockerfile 是由一系列命令和参数构成的脚本,这些命令应用于基础镜像并最终创建一个新的镜像. 对于开发人员:可以为开发团队提供一个完全一致的开发环境; 对于测试人 ...
- Nginx入门(二):镜像和容器
0.docker常用命令 #镜像名 版本标签 镜像id 创建时间 镜像大小 REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest fce289 ...
- ResourceManager基本职能和内部架构
YARN也采用了Master/Slave结构,其中,Master实现为ResourceManager,负责整个集群资源的管理与调度:Slave实现为NodeManager,负责单个节点的资源管理与任务 ...
- Oracle - 获取当前周别函数
CREATE OR REPLACE FUNCTION GET_WEEK (V_RQ in DATE) return varchar2 as str varchar2(); str1 varchar2( ...
- 混合图欧拉回路POJ1637Sightseeing tour
http://www.cnblogs.com/looker_acm/archive/2010/08/15/1799919.html /* ** 混合图欧拉回路 ** 只记录各定点的出度与入度之差,有向 ...