一、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

 package com.tuling.cloud.study;

 import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients; @EnableDiscoveryClient
@SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker //这样就可以使用/hystrix.stream端点监控Hystrix了
public class ConsumerOrderApplication_07_stream { public static void main(String[] args) {
SpringApplication.run(ConsumerOrderApplication_07_stream.class, args);
} }

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

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


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

dashBoard 是一个独立的项目:

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.tuling.cloud</groupId>
<artifactId>microservice-hystrix-dashboard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>07-ms-hystrix-dashboard</name> <!-- 引入spring boot的依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
    <!-- dashBoard包-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
</dependencies> <!-- 引入spring cloud的依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <!-- 添加spring-boot的maven插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

启动类:

 package com.jiagoushi.cloud.study;

 import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @SpringBootApplication
@EnableHystrixDashboard //DashBoard 支持
public class HystrixDashboardApplication { public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}

applciation.yml:

server:
port: 8030

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

在监控的界面有两个重要的图形信息:一个实心圆和一条曲线。
  实心圆:1、通过颜色的变化代表了实例的健康程度,健康程度从绿色、黄色、橙色、
      红色递减。

      2、通过大小表示请求流量发生变化,流量越大该实心圆就越大。所以可以在大
      量的实例中快速发现故障实例和高压实例。
  曲线:用来记录2分钟内流浪的相对变化,可以通过它来观察流量的上升和下降趋势



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

三、使用Turbine聚合监控数据

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

Turbine 独立的项目:

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.tuling.cloud</groupId>
<artifactId>microservice-hystrix-turbine</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>07-ms-hystrix-turbine</name> <!-- 引入spring boot的依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<!-- turbine 依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
</dependencies> <!-- 引入spring cloud的依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <!-- 添加spring-boot的maven插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

application.yml:

 server:
port: 8031
spring:
application:
name: microservice-hystrix-turbine
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
prefer-ip-address: true #turbine 配置
turbine:
appConfig: microservice-consumer-order,microservice-consumer-order-feign-hystrix-fallback-stream #微服务名称
clusterNameExpression: "'default'"

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:

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

欢迎来群592495675一起学习

springcloud(八) Hystrix监控的更多相关文章

  1. Spring-cloud (八) Hystrix 请求缓存的使用

    前言: 最近忙着微服务项目的开发,脱更了半个月多,今天项目的初版已经完成,所以打算继续我们的微服务学习,由于Hystrix这一块东西好多,只好多拆分几篇文章写,对于一般对性能要求不是很高的项目中,可以 ...

  2. springcloud(八)-Hystrix熔断器

    雪崩效应 在微服务架构中通常会有多个服务层调用,基础服务的故障可能会导致级联故障,进而造成整个系统不可用的情况,这种现象被称为服务雪崩效应.服务雪崩效应是一种因“服务提供者”的不可用导致“服务消费者” ...

  3. Spring Cloud(五):Hystrix 监控面板【Finchley 版】

    Spring Cloud(五):Hystrix 监控面板[Finchley 版]  发表于 2018-04-16 |  更新于 2018-05-10 |  在上一篇 Hystrix 的介绍中,我们提到 ...

  4. Spring Cloud(六):Hystrix 监控数据聚合 Turbine【Finchley 版】

    Spring Cloud(六):Hystrix 监控数据聚合 Turbine[Finchley 版]  发表于 2018-04-17 |  更新于 2018-05-07 |  上一篇我们介绍了使用 H ...

  5. Spring Cloud(Dalston.SR5)--Hystrix 监控

    在服务调用者加入 Actuator ,可以对服务调用者的健康情况进行实时监控,例如,断路器是否打开.当前负载情况等. 服务调用者 需要增加 actuator依赖, 修改 POM.xml 中增加以下依赖 ...

  6. SpringCloud使用Sofa-lookout监控(基于Eureka)

    本文介绍SpringCloud使用Sofa-lookout,基于Eureka服务发现. 1.前景 本文属于是前几篇文章的后续,其实一开始感觉这个没有什么必要写的,但是最近一个朋友问我关于这个的问题,所 ...

  7. spring cloud Hystrix监控面板Hystrix Dashboard和Turbine

    我们提到断路器是根据一段时间窗内的请求情况来判断并操作断路器的打开和关闭状态的.而这些请求情况的指标信息都是HystrixCommand和HystrixObservableCommand实例在执行过程 ...

  8. 基于Prometheus搭建SpringCloud全方位立体监控体系

    前提 最近公司在联合运维做一套全方位监控的系统,应用集群的技术栈是SpringCloud体系.虽然本人没有参与具体基础架构的研发,但是从应用引入的包和一些资料的查阅大致推算出具体的实现方案,这里做一次 ...

  9. 高并发场景-请求合并(一)SpringCloud中Hystrix请求合并

    背景 在互联网的高并发场景下,请求会非常多,但是数据库连接池比较少,或者说需要减少CPU压力,减少处理逻辑的,需要把单个查询,用某些手段,改为批量查询多个后返回. 如:支付宝中,查询"个人信 ...

随机推荐

  1. AtomicLong可以被原子地读取和写入的底层long值的操作

    java.util.concurrent.atomic.AtomicLong类提供了可以被原子地读取和写入的底层long值的操作,并且还包含高级原子操作. AtomicLong支持基础long类型变量 ...

  2. EF大数据批量添加性能问题(续)

    昨天在园子里发了一篇如题的文章EF大数据批量添加性能问题,就引来一大堆的吐槽,我认为知识就应该这样分享出来,不然总以为自己很了不起:再说说昨天那篇文章,很多自认为很牛逼的人都评论说把SaveChang ...

  3. 如果从excel表中导出insert-sql

    =CONCATENATE("INSERT INTO p_act_lottery(actId,status,grantWay,createTime,invalidTime,amount,pri ...

  4. Spring 调度任务@scheduled学习总结

    官网Api:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html#sche ...

  5. 两个值相等的Integer的==比较问题

    @Test    public void testIntegerEqual() {        /** -128~127 之外的数**/        Integer tem = 129;      ...

  6. vue 父组件传递数据给子组件

    父组件 <body> <div id="app"> <child v-bind:data = "test"></chi ...

  7. 20181009-2 选题 Scrum立会报告+燃尽图(01)

    Scrum立会报告+燃尽图(01)选题 此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2190 一.小组介绍 组长:刘莹莹 ...

  8. Mysql查询正在运行的事务以及杀掉它

    查询 正在执行的事务:SELECT * FROM information_schema.INNODB_TRX 根据这个事务的线程ID(trx_mysql_thread_id): 可以使用mysql命令 ...

  9. Ubuntu下制作系统启动盘

    制作系统U盘: $ sudo umount /dev/sdc1 $ -desktop-amd64.iso of=/dev/sdc + records in + records out bytes (1 ...

  10. Oozie_01安装教程【20161116】

    说明:hadoop用的是hadoop-2.5.0-cdh5.3.6 Oozie用的是oozie-4.0.0-cdh5.3.6 该测试环境用户名为hadoop  主机名为hadoop01 2.4安装部署 ...