一、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. [原][osgearth]osgearthviewer读取earth文件,代码解析(earth文件读取的一帧)

    跑osgearthviewer程序 使用一个earth文件做参数传入 跟进代码. 首先osgearthviewer程序加载earth的方式分为两种: 1.根据earth文件(load方式) 2.使用S ...

  2. mysql安装不上怎么办 mysql安装失败原因和解决方法

    困难1:MySQL 5.1 安装过程中报apply security setting错误 1.卸载MySQL. 2.删除目录 C:\Documents and Settings\All Users\A ...

  3. vscode的keybindings.json 和 AHK 脚本映射Win键

    vscodehotkey.ahk https://github.com/m2nlight/AHKVSCodeLikeMac ; Shortcuts like mac ; Written by Bob ...

  4. StringUtils 正则校验

    public class StringUtils { /** * 如果str为null,返回“”,否则返回str * @param str * @return */ public static Str ...

  5. codeforce——因数筛

    题目大意:给你一个 n 和 k 求 n 的第 k 个因数. #include<iostream> #include <algorithm> #include <queue ...

  6. python模块之ConfigParser: 用python解析配置文件

    在程序中使用配置文件来灵活的配置一些参数是一件很常见的事情,配置文件的解析并不复杂,在python里更是如此,在官方发布的库中就包含有做这件事情的库,那就是ConfigParser,这里简单的做一些介 ...

  7. C++轮子队

    团队Github地址:https://github.com/Pryriat/2048.git 团队展示: 队名:C++轮子队 队员组成: 黄家承(队长)              学号:3116005 ...

  8. 5.3 将users表添加到xadmin后台

    在users模块中添加adminx.py文件,是xadmin后台管理默认的文件名,内容是: from .models import EmailVerifyRecord, Banner import x ...

  9. 最大流之dinic

    先用bfs预处理出层次图,然后在层次图上用dfs找增广路径,理论复杂度O(n*n*m) const int INF=0xfffffff ; struct node { int s,t,cap,nxt ...

  10. java阳历转农历

    package com.reading.task; import java.text.ParseException;import java.text.SimpleDateFormat;import j ...