Spring Cloud Hystrix Dashboard仪表盘 和 Turbine集群监控 (学习总结)
一、简介
Spring Cloud Hystrix Dashboard是一个可以监控HystrixCommand的可视化图形界面,由于某种原因,如网络延迟、服务故障等,这时候可以借助dashboard提供的可视化界面监控各个Hystrix执行的成功率、调用成功数、失败数量、最近十分钟的流量图等等,根据这些数据我们就可以进行错误排查以及进行服务的优化等。Hystrix Dashboard只能对单个服务进行监控,实际项目中,服务通常集群部署,这时候可以借助Turbine进行多个服务的监控。
二、准备工程
hystrix-server:eureka服务注册中心,端口1111,本文不做介绍
hystrix-dashboard1:进行hystrix监控的服务1 端口3333
hystrix-dashboard2:进行hystrix监控的服务2 端口5555
hystrix-turbine:turbine集群监控项目 端口4444
接下来先讲讲单个服务的监控:
三、新建hystrix-dashboard1项目
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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><groupId>com.springcloud.wsh</groupId><artifactId>springcloud_hystrix_dashboard</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>springcloud_hystrix_dashboard</name><description>Spring Cloud Hystrx Dashboard仪表盘</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.2.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Camden.SR6</spring-cloud.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-ribbon</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix-dashboard</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
四、启动类加上@EnableHystrixDashboard注解
/*** @Description: 单个服务的Hystrix监控* @Author: WeiShiHuai* @Date: 2018/9/13 15:30
*/
//@SpringBootApplication
//@EnableCircuitBreaker
//@EnableDiscoveryClient
@SpringCloudApplication
@EnableHystrixDashboard
public class SpringcloudHystrixDashboardApplication {public static void main(String[] args) {SpringApplication.run(SpringcloudHystrixDashboardApplication.class, args);}@Bean@LoadBalancedRestTemplate restTemplate() {return new RestTemplate();}
}
五、新建HystrixController
提供一个/hello的接口,并且使用@HystrixCommand注解修饰,指定Hystrix服务降级处理方法
/*** @Title: HystrixController* @ProjectName springcloud_hystrix_dashboard* @Description: 测试* @Author WeiShiHuai* @Date 2018/9/13 15:48*/
@RestController
public class HystrixController {private static Logger logger = LoggerFactory.getLogger(HystrixController.class);@RequestMapping("/hello")@HystrixCommand(fallbackMethod = "hiError")public String hello(@RequestParam String name) {return "hello, " + name;}public String helloError(String name) {return "hello, " + name + ",sorry,error!";}
}
六、配置文件
server:port: 3333
spring:application:name: hystrix-dashboard1
eureka:client:service-url:defaultZone: http://localhost:1111/eureka/
七、启动eureka-server以及hystrix-dashboard1项目
首先我们先访问http://localhost:3333/hello?name=weixiaohuai,如下图:
可以看到,接口已经调用成功,接着我们访问:http://localhost:3333/hystrix,进入hystrix监控界面:如下图
此时我们在监控地址栏输入:http://localhost:3333/hystrix.stream,如下图
点击Monitor Stream,进入到Dashboard仪表盘实时监控页面,这个时候我们需要请求一下接口http://localhost:3333/hello?name=weixiaohuai,这样仪表盘才能监控到请求的一些数据信息。
监控界面实时展示了两分钟内接口请求的流量、请求成功百分比、成功数、失败数、超时数等等。至此,单服务的Hystrix监控已经实现。接下来看一下集群监控Turbine的实现方法:
八、新建hystrix-dashboard2工程
端口5555,只是端口与hystrix-dashboard1工程不一致,其他与hystrix-dashboard1都一样,下面直接贴代码:
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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><groupId>com.springcloud.wsh</groupId><artifactId>springcloud_hystrix_dashboard2</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>springcloud_hystrix_dashboard2</name><description>Demo project for Spring Boot</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.2.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Camden.SR6</spring-cloud.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-ribbon</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix-dashboard</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
配置文件:
server:port: 5555
spring:application:name: hystrix-dashboard2
eureka:client:service-url:defaultZone: http://localhost:1111/eureka/
启动类:
@SpringCloudApplication
@EnableHystrixDashboard
public class SpringcloudHystrixDashboard2Application {public static void main(String[] args) {SpringApplication.run(SpringcloudHystrixDashboard2Application.class, args);}@Bean@LoadBalancedRestTemplate restTemplate() {return new RestTemplate();}
}
HystrixController2:
/*** @Title: HystrixController* @ProjectName springcloud_hystrix_dashboard* @Description: 测试* @Author WeiShiHuai* @Date 2018/9/13 15:48*/
@RestController
public class HystrixController2 {private static Logger logger = LoggerFactory.getLogger(HystrixController2.class);@RequestMapping("/hello")@HystrixCommand(fallbackMethod = "helloError")public String hello(@RequestParam String name) {return "hello, " + name;}public String helloError(String name) {return "hello, " + name + ",sorry,error!";}
}
九、新建hystrix-turbine工程
端口4444,注意要引入turbine的依赖:
<?xml version="1.0" encoding="UTF-8"?>
<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><groupId>com.springcloud.wsh</groupId><artifactId>springcloud_turbine</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>springcloud_turbine</name><description>Spring Cloud Turbine集群监控</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.2.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Camden.SR6</spring-cloud.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-turbine</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
十、启动类加上@EnableTurbine注解开启Turbine集群监控功能
@SpringBootApplication
@EnableTurbine
public class SpringcloudTurbineApplication {public static void main(String[] args) {SpringApplication.run(SpringcloudTurbineApplication.class, args);}
}
十一、turbine的配置文件
server:port: 4444
spring:application:name: hystrix-turbine
eureka:client:service-url:defaultZone: http://localhost:1111/eureka/
turbine:# 配置注册到Eureka中的serviceId列表,表明监控哪些服务app-config: hystrix-dashboard1,hystrix-dashboard2cluster-name-expression: new String("default")# 1. clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称# 2. 当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default# 3. 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC,则需要配置,同时turbine.aggregator.clusterConfig: ABC#aggregator:#clusterConfig: default # 指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问
注意:通过turbine.appConfig指定我们需要监控哪些服务,这里对应注册到Eureka中的名称,即application-name(serviceId)
十二、启动项目eureka-server,hystrix-dashboard1,hystrix-dashhystrix2以及hystrix-turbine
浏览器访问:http://localhost:3333/hello?name=weixiaohuai、http://localhost:5555/hello?name=helloworld
我们随机访问一下这两个服务的接口,接着我们浏览器输入http://localhost:3333/hystrix进入到hystrix监控页面(http://localhost:5555/hystrix也可以),在监控地址栏输入:http://localhost:4444/turbine.stream
可以看到,turbine已经实现了对HystrixController、HystrixController2的集群监控。
十三、总结
其实,在实际项目中,这种实时监控有点耗性能,通常采用消息中间件如RabbitMQ等,我们接口调用把Hystrix的一些信息收集到RabbitMQ中,然后Turbine从RabbitMQ中获取监控的数据。本文主要讲解dashboard和turbine的基本使用方法,对于一些高级用法,还有待研究。。。
Spring Cloud Hystrix Dashboard仪表盘 和 Turbine集群监控 (学习总结)相关推荐
- Spring Cloud中Hystrix仪表盘与Turbine集群监控
Hystrix仪表盘,就像汽车的仪表盘实时显示汽车的各项数据一样,Hystrix仪表盘主要用来监控Hystrix的实时运行状态,通过它我们可以看到Hystrix的各项指标信息,从而快速发现系统中存在的 ...
- Spring Cloud中Hystrix仪表盘与Turbine集群监控 1
Hystrix仪表盘,就像汽车的仪表盘实时显示汽车的各项数据一样,Hystrix仪表盘主要用来监控Hystrix的实时运行状态,通过它我们可以看到Hystrix的各项指标信息,从而快速发现系统中存在的 ...
- Spring Cloud Turbine集群监控一直Loading问题
这是最近在 学习Spring Cloud 按照书或者网上的例子敲示例遇到的问题,这个问题网上有很多答案,但是我遇到的问题和其他人不同, 如果你也遇到类似问题,希望下面的解决方法能帮助到你 问题描述: ...
- 服务容错保护断路器Hystrix之四:断路器监控(Hystrix Dashboard)-turbine集群监控
turbine 英[ˈtɜ:baɪn] n. 汽轮机; 涡轮机; 透平机; OK,上文我们看了一个监控单体应用的例子,在实际应用中,我们要监控的应用往往是一个集群,这个时候我们就得采取Turbine集 ...
- 疯狂Spring Cloud连载(5)Eureka集群搭建
2019独角兽企业重金招聘Python工程师标准>>> 本文节选自<疯狂Spring Cloud微服务架构实战> 京东购买地址:https://item.jd.com/1 ...
- Turbine集群监控
一 turbine简介 Hystrix Dashboard首页提到监控端点/turbine.stream,它是用来监控集群的.从端点的命名来看,它需要引入Turbine,通过它来汇集监控信息,并将聚合 ...
- Spring Cloud Hystrix理解与实践(一):搭建简单监控集群
前言 在分布式架构中,所谓的断路器模式是指当某个服务发生故障之后,通过断路器的故障监控,向调用方返回一个错误响应,这样就不会使得线程因调用故障服务被长时间占用不释放,避免故障的继续蔓延.Spring ...
- Spring Cloud 2.x系列之Feign整合断路器监控Hystrix Dashboard
SVN多版本库环境的搭建 OAuth 2.0是什么?看这篇文章就够了. 前端 Java Python等资源合集大放送 Ribbon可以整合整合断路器监控Hystrix Dashboard,Feign也 ...
- Spring Cloud 入门——6.1 Turbine 集群数据监控
代码信息 本篇文章涉及代码版本 组件 版本 Spring Boot 2.0.8.RELEASE Spring Cloud Finchley.SR1 本篇文章涉及应用 应用 说明 base-eureka ...
- Hystrix 集群 及 集群监控 Turbine
Hystrix 集群 及 集群监控 turbine Hystrix 集群及监控 turbine Feign.Hystrix整合 集群后超时设置 本章知识: 1.Hystrix集群及监控turbine ...
最新文章
- 李联宁|量子计算机:技术路线、风险及战略投资
- 使用libcurl库编写HTTP客户端(包括GET/POST/HTTPS)
- php 解析 js new date,js new Date() 测试
- QT的QListWidget类的使用
- window.onload,body onload=function(), document.onreadystatechange, httpRequest.onreadystatechang
- 让 AI 为你写代码 - 体验 Github Copilot
- Java代码样式运算符换行格式
- 一起看一下主流应用使用了哪些三方库
- 机器学习公开课笔记(8):k-means聚类和PCA降维
- centos 5.6安装nginx+mysql+php(php-fpm)+phpmyadmin总结
- 【QT】QT从零入门教程(一):图像处理自编软件
- 软件测试基础 (一): 单元测试
- JXLS for循环
- 仿弹个课教育类APP项目,客户端+服务端
- 《MFC 控件透明处理》
- JSCH连接SFTP Algorithm negotiation fail
- Python 集和篇
- 利用计算机及网络系统支持考试的方式是,2012年7月全国自主考试(网络操作系统)真题...
- Python Gstreamer播放rtsp视频流(海康IPCAM)
- 网页期末作业 基于HTML+CSS中国传统节日【清明节】带论文8000字
热门文章
- matlab中单位格式,[转载]matlab中的数据显示格式-format
- php三元运算符应用举例,php – 使用嵌套三元运算符
- PySpark: DataProcessing(csv file)
- 阿里云云计算 33 PolarDB的优势 产品架构
- TensorFlow by Google一个计算机视觉示例Machine Learning Foundations: Ep #2 - First steps in computer vision
- mysql删完数据表空间没释放_mysql删除表后,空间一直不释放
- 微型计算机主机作用,微型计算机的主机包括()。
- 足球比赛两强相遇概率
- 利用反射给属性赋值,调用方法,调用构造器--getDeclaredField,getDeclaredMethod,getDeclardConstructor
- 【GNN框架系列】DGL第二讲:使用Deep Graph Library实现GNN进行链接预测