spring cloud的hystrix还有一个配搭的库hystrix-dashboard,它是hystrix的一款监控工具,能直观的显示hystrix响应信息,请求成功率等.但是hystrix-dashboard只能查看单机和集群的信息,如果需要将多台的信息汇总起来的话就需要使用turbine.

注:这一个系列的开发环境版本为 java1.8, spring boot2.x, spring cloud Greenwich.SR2, IDE为 Intelli IDEA

hystrix-dashboard

hystrix-dashboard只要在上一篇的hystrix的基础上稍微修改下就可以了.

添加依赖

依赖文件pom.xml需要添加一些信息.

        <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

需改启动类

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.xingyys.hystrix.remote")
// 添加以下注解
@EnableHystrixDashboard
@EnableCircuitBreaker
public class HystrixApplication { public static void main(String[] args) {
SpringApplication.run(HystrixApplication.class, args);
} }

修改配置文件

spring cloud 2.x版本和1.x版本不同,需要修改配置文件

# ......
# application.properties
management.endpoints.web.exposure.include=hystrix.stream
management.endpoints.web.base-path=/

测试

重新编译后开始测试

浏览器访问http://127.0.0.1:9002/hystrix出现以下页面:

浏览器访问: http://127.0.0.1:9002/hystrix.stream出现以下信息

ping: 

data: {...}

data: {...}

同时在http://192.168.1.13:9002/hystrix页面中检测http://127.0.0.1:9002/hystrix.stream ,点击monitor stream跳转页面:



hystrix-dashboard显示的各项信息含义:



到这里,单节点的监控就完成了.

注:如果一直显示Loading..., 刷新 http://127.0.0.1:9002/hello/xxx页面即可.

turbine

接下来我们来看看在多台节点中的监控工具Turbine是如何配置.

创建工程

首先我们还是先来创建一个工程应用,命名为turbine

依赖文件

修改依赖文件pom.xml

    <properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-turbine</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</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>

配置文件

修改配置文件application.propertoes

spring.application.name=turbine

server.port=8081
# 配置Eureka中的serviceId列表,表明监控哪些服务 turbine.app-config=node01,node02
# 指定聚合哪些集群,多个使用”,”分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问 turbine.aggregator.cluster-config=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
turbine.cluster-name-expression=new String("default") eureka.client.service-url.defaultZone=http://localhost:8000/eureka # spring cloud 2.x版本需要作的改动
management.endpoints.web.exposure.include=turbine.stream
management.endpoints.web.base-path=/

启动类

@SpringBootApplication
@EnableHystrixDashboard
// 激活对turbine的支持
@EnableTurbine
public class TurbineApplication { public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
} }

测试

开始测试前,需要对hystrix应用做修改,添加两个配置文件application-node01.properitesapplication-node02.properties.

application-node01.properites

spring.application.name=node01

server.port=9003
# 其他和consumer相同,主要是hystrix的配置
feign.hystrix.enabled=true eureka.client.service-url.defaultZone=http://localhost:8000/eureka/ management.endpoints.web.exposure.include=hystrix.stream
management.endpoints.web.base-path=/

application-node02.properites

spring.application.name=node02

server.port=9004
# 其他和consumer相同,主要是hystrix的配置
feign.hystrix.enabled=true eureka.client.service-url.defaultZone=http://localhost:8000/eureka/ management.endpoints.web.exposure.include=hystrix.stream
management.endpoints.web.base-path=/

hystrix启动类

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.xingyys.hystrix.remote")
@EnableHystrixDashboard
@EnableCircuitBreaker
public class HystrixApplication {
// spring cloud 2.x需要自己指定
@Bean(name = "HystrixMetricsStreamServlet")
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
} public static void main(String[] args) {
SpringApplication.run(HystrixApplication.class, args);
} }

以此启动应用:

java -jar target/discovery-0.0.1-SNAPSHOT.jar
java -jar target/hystrix-0.0.1-SNAPSHOT.jar --spring.profiles.active=node01
java -jar target/hystrix-0.0.1-SNAPSHOT.jar --spring.profiles.active=node02
java -jar target/turbine-0.0.1-SNAPSHOT.jar

访问http://127.0.0.1:8081/turbine.stream,返回

: ping

: ping

访问http://127.0.0.1:8081/hystrix并填写表单,出现以下页面:

注:假如一直在loading,请刷新node01或node02节点的/hello/neo页面,但要保证服务的提供应用关闭.

spring cloud微服务实践四的更多相关文章

  1. spring cloud微服务实践二

    在上一篇,我们已经搭建了spring cloud微服务中的注册中心.但只有一个注册中心还远远不够. 接下来我们就来尝试提供服务. 注:这一个系列的开发环境版本为 java1.8, spring boo ...

  2. spring cloud微服务实践七

    在spring cloud 2.x以后,由于zuul一直停滞在1.x版本,所以spring官方就自己开发了一个项目 Spring Cloud Gateway.作为spring cloud微服务的网关组 ...

  3. spring cloud微服务实践五

    本篇我们来看看怎么实现spring cloud的配置中心. 在分布式系统中,特别是微服务架构下,可能会存在许多的服务,每个服务都会存在一个或多个的配置文件.那怎么多的配置文件的管理就会成为一个大问题. ...

  4. spring cloud微服务实践六

    本片我们就来认识下spring cloud中的zuul组件. 注:这一个系列的开发环境版本为 java1.8, spring boot2.x, spring cloud Greenwich.SR2, ...

  5. spring cloud微服务实践一

    最近在学习spring框架.其中spring cloud在微服务方面很火,所以在学习过程中,也做一些记录. 注:这一个系列的开发环境版本为 java1.8, spring boot2.x, sprin ...

  6. spring cloud微服务实践三

    上篇文章里我们实现了spring cloud中的服务提供者和使用者.接下来我们就来看看spring cloud中微服务的其他组件. 注:这一个系列的开发环境版本为 java1.8, spring bo ...

  7. Spring Cloud微服务实践之路-起始

    由于各种原因,公司要对现有的营销产品进行微服务化,如果可以,则对公司所有产品逐步进行微服务化. 而本人将探索这条路,很艰难,但干劲十足.整个过会记录下来,以便以后查阅. 感谢公司!感谢领导! 相关书籍 ...

  8. Spring Cloud微服务实践之路- Eureka Server 中的第一个异常

    EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER ...

  9. 放弃Dubbo,选择最流行的Spring Cloud微服务架构实践与经验总结

    http://developer.51cto.com/art/201710/554633.htm Spring Cloud 在国内中小型公司能用起来吗?从 2016 年初一直到现在,我们在这条路上已经 ...

随机推荐

  1. Linux开机、重启、和用户登录注销

    一. 关机&重启命令 基本介绍: shutdown shutdown –h now    :   表示立即关机 shutdown -h          : 表示1分钟后关机 shutdown ...

  2. centos6和centos7中常用命令区别

    以前一直接触的是centos6,最近因为新项目接触到centos7,发现有些命令还是有差异的(从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig),现 ...

  3. 2018-2019-2 20165222《网络对抗技术》Exp9 Web安全基础

    1.实践过程记录 1.字符串型注入. 2.整数型注入 3.注入语句查看其他内容 4.xss是一种漏洞,这种漏洞允许用户输入脚本并且浏览器提交的时候不加编码.这种东西是最为流行并且有害的web应用的问题 ...

  4. 神经网络模型(Backbone)

    自己搭建神经网络时,一般都采用已有的网络模型,在其基础上进行修改.从2012年的AlexNet出现,如今已经出现许多优秀的网络模型,如下图所示. 主要有三个发展方向: Deeper:网络层数更深,代表 ...

  5. raid卷性能测试

    #RAID卷 独立磁盘冗余阵列RAID是一种把多块独立的硬盘(物理硬盘)按不同的方式组合起来形成一个硬盘组(逻辑硬盘),从而提供比单个硬盘更高的存储性能和提供数据备份技术.组成磁盘阵列的不同方式成为R ...

  6. 二维背包---P1509 找啊找啊找GF

    P1509 找啊找啊找GF 题解 很明显这是一道二维背包题目 如果一个dp数组做不了,那么我们就再来一个dp数组 题目要求,花费不超过 m ,消耗人品不超过  r  ,泡到尽量多的妹子,时间尽量少 f ...

  7. Dataeye计算任务架构

    https://mp.weixin.qq.com/s/9Q5-oU3bPIBieScwzrawDg 资源消耗降低2/3,Flink在唯品会实时平台的应用(有彩蛋) 王新春 DBAplus社群 2018 ...

  8. SpringBoot+Mybatis+Maven+MySql小案例

    数据准备: 建表t_user ,插入数据..... 创建工程 构建pom.xml <?xml version="1.0" encoding="UTF-8" ...

  9. 阶段5 3.微服务项目【学成在线】_day18 用户授权_19-微服务之间认证-Feign 拦截器

    4.2 Feign 拦截器 4.2.1 定义Feign拦截器 微服务之间使用feign进行远程调用,采用feign拦截器实现远程调用携带JWT. 在common工程添加依赖: <dependen ...

  10. 123456123456#0#-----com.threeapp.xiongMaoPaoPao01----熊猫跑酷01

    com.threeapp.xiongMaoPaoPao01----熊猫跑酷01