springcloud(八) Hystrix监控

Easter79
• 阅读 604

一、Feign项目Hystrix自带的监控

在feign项目pom.xml 添加:

<!--  1,使用 Hystrix的模块 hystrix-metrics-event-stream,就可将这些监控的指标信息以    text/event-stream的格式暴露给外部系统。 spring-cloud-starter-netflix-hystrix包含该    模块,在此基础上,只须为项目添加 spring-boot-starter-actuator依赖,就可使    用/hystrix.stream端点获得Hystrix的监控信息了。      2, Feign项目的Hystrix监控-->

  <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    </dependency>

<!-- 健康度jar--><dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-actuator</artifactId></dependency>

注意之前Feign项目整合Hystrix时pom依赖是这样的:

<!-- 虽然Feign已经依赖Hystrix-core 但是想要监控还是不够的 要引入整个Hystrix-->   <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

Feign项目启动类需要添加注解 @EnableCircuitBreaker

 1 package com.tuling.cloud.study;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
 5 import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
 6 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 7 import org.springframework.cloud.netflix.feign.EnableFeignClients;
 8 
 9 @EnableDiscoveryClient
10 @SpringBootApplication
11 @EnableFeignClients
12 @EnableCircuitBreaker   //这样就可以使用/hystrix.stream端点监控Hystrix了
13 public class ConsumerOrderApplication_07_stream {
14 
15   public static void main(String[] args) {
16     SpringApplication.run(ConsumerOrderApplication_07_stream.class, args);
17   }
18 
19 }

启动之后访问Feign 项目 : http://localhost:9020/hystrix.stream 是这样的:

springcloud(八) Hystrix监控

这种监控数据没法看,对吧?


 二、使用Hystrix Dashboard可视化监控数据

dashBoard 是一个独立的项目:

springcloud(八) Hystrix监控

pom.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4   <modelVersion>4.0.0</modelVersion>
 5   <groupId>com.tuling.cloud</groupId>
 6   <artifactId>microservice-hystrix-dashboard</artifactId>
 7   <version>0.0.1-SNAPSHOT</version>
 8   <packaging>jar</packaging>
 9   <name>07-ms-hystrix-dashboard</name>
10 
11   <!-- 引入spring boot的依赖 -->
12   <parent>
13     <groupId>org.springframework.boot</groupId>
14     <artifactId>spring-boot-starter-parent</artifactId>
15     <version>1.5.9.RELEASE</version>
16   </parent>
17 
18   <properties>
19     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20     <java.version>1.8</java.version>
21   </properties>
22 
23   <dependencies>    <!-- dashBoard包-->
24     <dependency>
25       <groupId>org.springframework.cloud</groupId>
26       <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
27     </dependency>
28   </dependencies>
29 
30   <!-- 引入spring cloud的依赖 -->
31   <dependencyManagement>
32     <dependencies>
33       <dependency>
34         <groupId>org.springframework.cloud</groupId>
35         <artifactId>spring-cloud-dependencies</artifactId>
36         <version>Edgware.RELEASE</version>
37         <type>pom</type>
38         <scope>import</scope>
39       </dependency>
40     </dependencies>
41   </dependencyManagement>
42 
43   <!-- 添加spring-boot的maven插件 -->
44   <build>
45     <plugins>
46       <plugin>
47         <groupId>org.springframework.boot</groupId>
48         <artifactId>spring-boot-maven-plugin</artifactId>
49       </plugin>
50     </plugins>
51   </build>
52 </project>

启动类:

 1 package com.jiagoushi.cloud.study;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
 5 import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
 6 
 7 @SpringBootApplication
 8 @EnableHystrixDashboard //DashBoard 支持
 9 public class HystrixDashboardApplication {
10 
11   public static void main(String[] args) {
12     SpringApplication.run(HystrixDashboardApplication.class, args);
13   }
14 }

applciation.yml:

server:
  port: 8030

启动之后访问:http://localhost:8030/hystrix

springcloud(八) Hystrix监控

springcloud(八) Hystrix监控

在监控的界面有两个重要的图形信息:一个实心圆和一条曲线。

  实心圆:1、通过颜色的变化代表了实例的健康程度,健康程度从绿色、黄色、橙色、
      红色递减。

2、通过大小表示请求流量发生变化,流量越大该实心圆就越大。所以可以在大

      量的实例中快速发现故障实例和高压实例。
  曲线:用来记录2分钟内流浪的相对变化,可以通过它来观察流量的上升和下降趋势


在复杂的分布式系统中,相同服务的节点经常需要部署上百甚至上千个,很多时候,运维人员希望能够把相同服务的节点状态以一个整体集群的形式展现出来,这样可以更好的把握整个系统的状态。 为此,Netflix提供了一个开源项目(Turbine)

来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。

三、使用Turbine聚合监控数据

Turbine是一个聚合 Hystrix监控数据的工具,它可将所有相关/hystrix.stream端点的数据聚合到一个组合的/turbine.stream中,从而让集群的监控更加方便

Turbine 独立的项目:

springcloud(八) Hystrix监控

pom.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4   <modelVersion>4.0.0</modelVersion>
 5   <groupId>com.tuling.cloud</groupId>
 6   <artifactId>microservice-hystrix-turbine</artifactId>
 7   <version>0.0.1-SNAPSHOT</version>
 8   <packaging>jar</packaging>
 9   <name>07-ms-hystrix-turbine</name>
10 
11   <!-- 引入spring boot的依赖 -->
12   <parent>
13     <groupId>org.springframework.boot</groupId>
14     <artifactId>spring-boot-starter-parent</artifactId>
15     <version>1.5.9.RELEASE</version>
16   </parent>
17 
18   <properties>
19     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20     <java.version>1.8</java.version>
21   </properties>
22 
23   <dependencies>
24     <!-- turbine 依赖-->
25     <dependency>
26       <groupId>org.springframework.cloud</groupId>
27       <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
28     </dependency>
29   </dependencies>
30 
31   <!-- 引入spring cloud的依赖 -->
32   <dependencyManagement>
33     <dependencies>
34       <dependency>
35         <groupId>org.springframework.cloud</groupId>
36         <artifactId>spring-cloud-dependencies</artifactId>
37         <version>Edgware.RELEASE</version>
38         <type>pom</type>
39         <scope>import</scope>
40       </dependency>
41     </dependencies>
42   </dependencyManagement>
43 
44   <!-- 添加spring-boot的maven插件 -->
45   <build>
46     <plugins>
47       <plugin>
48         <groupId>org.springframework.boot</groupId>
49         <artifactId>spring-boot-maven-plugin</artifactId>
50       </plugin>
51     </plugins>
52   </build>
53 </project>

application.yml:

 1 server:
 2   port: 8031
 3 spring:
 4   application:
 5     name: microservice-hystrix-turbine
 6 eureka:
 7   client:
 8     service-url:
 9       defaultZone: http://localhost:8761/eureka/
10   instance:
11     prefer-ip-address: true
12 
13 #turbine 配置
14 turbine:
15   appConfig: microservice-consumer-order,microservice-consumer-order-feign-hystrix-fallback-stream  #微服务名称
16   clusterNameExpression: "'default'"
17   
18   
19

Turbine 为什么要链接注册中心?

Turbine会在Eureka Server中找到 microservice-consumer-order和 microservice-consumer-order-feign-hystrix-fallback-stream这两个微服务,并聚合两个微服务的监控数据

 

TurbineApplication 启动类:

package com.jiagoushi.cloud.study;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@SpringBootApplication
@EnableTurbine  //开启turbine
public class TurbineApplication {
  public static void main(String[] args) {
    SpringApplication.run(TurbineApplication.class, args);
  }
}

启动Tuibine:

springcloud(八) Hystrix监控

springcloud(八) Hystrix监控

如果我们把user服务关闭了,那么监控就是这样的:

springcloud(八) Hystrix监控

欢迎来群592495675一起学习

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Easter79 Easter79
2年前
springcloud feign集成hystrix
本章介绍feign集成hystrix1、增加pom依赖\<dependency<groupidorg.springframework.cloud</groupid<artifactidspringcloudstarternetflixhystrix</artifactid</
Stella981 Stella981
2年前
Feign请求响应结果被截取com.fasterxml.jackson.core.io.JsonEOFException
在生产环境使用feign调用外部接口时,偶尔会出现下面错误2020101511:00:18,535ERRORcom.shein.abc.rmp.controller.RecExplainConfigControllerrec_explain_query.failffeign.codec.DecodeExc
Easter79 Easter79
2年前
SpringCloud入门(七)
Hystrix提供了HystrixDashboard来实时监控HystrixCommand方法的执行情况。HystrixDashboard可以有效地反映出每个Hystrix实例的运行情况,帮助我们快速发现系统中的问题,从而采取对应措施。使用熔断器仪表盘监控在Ribbon和Feign项目增加Hystrix仪表盘功能,两个项目的改造方式相同。
Easter79 Easter79
2年前
SpringCloud(第 016 篇)电影微服务,定制Feign,一个Feign功能禁用Hystrix,另一个Feign功能启用Hystrix
SpringCloud(第016篇)电影微服务,定制Feign,一个Feign功能禁用Hystrix,另一个Feign功能启用Hystrix一、大致介绍1、在一些场景中,部分功能需
Stella981 Stella981
2年前
Hystrix的使用1
Hystrix的使用1简介以下文章照搬自Hystrix官网介绍(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2FNetflix%2FHystrix%2Fwiki)1.什么是Hystrix?在
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k