`
234390216
  • 浏览: 10218592 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
博客专栏
A5ee55b9-a463-3d09-9c78-0c0cf33198cd
Oracle基础
浏览量:462009
Ad26f909-6440-35a9-b4e9-9aea825bd38e
springMVC介绍
浏览量:1774424
Ce363057-ae4d-3ee1-bb46-e7b51a722a4b
Mybatis简介
浏览量:1397489
Bdeb91ad-cf8a-3fe9-942a-3710073b4000
Spring整合JMS
浏览量:394699
5cbbde67-7cd5-313c-95c2-4185389601e7
Ehcache简介
浏览量:679501
Cc1c0708-ccc2-3d20-ba47-d40e04440682
Cas简介
浏览量:530288
51592fc3-854c-34f4-9eff-cb82d993ab3a
Spring Securi...
浏览量:1180700
23e1c30e-ef8c-3702-aa3c-e83277ffca91
Spring基础知识
浏览量:465997
4af1c81c-eb9d-365f-b759-07685a32156e
Spring Aop介绍
浏览量:151028
2f926891-9e7a-3ce2-a074-3acb2aaf2584
JAXB简介
浏览量:67732
社区版块
存档分类
最新评论

Spring Cloud(07)——Hystrix Dashboard

阅读更多

Hystrix Dashboard

Spring Cloud也基于Spring Boot的监控规范提供了Hystrix的指标监控信息。为了看到这些监控信息,首先需要在pom.xml中添加如下依赖。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Spring Cloud提供的Hystrix监控信息的endpoint ID是hystrix.stream,为了看到对应的监控信息,还需要把Hystrix对应的endpoint以http的方式发布出来。可以以下面的方式明确的指定需要发布hystrix.stream

management.endpoints.web.exposure.include=hystrix.stream

也可以直接指定发布所有的endpoint。

management.endpoints.web.exposure.include=*

发布了hystrix.stream后,跟其它endpoint一样,可以通过/actuator/endpointId获取对应endpoint发布的信息,所以可以通过/actuator/hystrix.stream访问到Hystrix发布的监控信息,此时可以看到类似如下这样的信息。

hystrix.stream

你也可能看到界面上一直显示的是ping:,这是因为应用刚启动,还没有对@HystrixCommand标注的方法发起请求,还没有产生对应的信息。

hystrix.stream直接看到的是JSON格式的数据,不直观。Hystrix有对应的图形监控界面,Spring Cloud也实现了对其的整合。使用图形监控界面需要在pom.xml中添加如下依赖。

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

然后在配置类上加上@EnableHystrixDashboard以启用对dashboard的支持。

@SpringBootApplication
@EnableHystrixDashboard
@EnableCircuitBreaker
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

之后可以通过/hystrix访问到监控界面的首页,你会看到如下界面。

Hystrix Dashboard

如上图红色标记部分所示,单机版访问的收集监控信息的地址是http://hystrix-app:port/actuator/hystrix.stream格式,笔者的应用部署在本机的8900端口,所以笔者收集监控信息的地址是http://localhost:8900/actuator/hystrix.stream,把它填入到第一个输入框,然后点击按钮Monitor Stream开始监控,你会看到类似如下界面。

Hystrix Dashboard Monitor

在这个监控页面中可以看到各@HystrixCommand对应的断路器的状态,各请求的耗时情况,失败率,以及对应的线程池的状态等。

 

turbine

hystrix.stream只能看到单个应用的监控信息。通常同一个服务会部署多份,使用hystrix.stream查看每个单个应用的情况会比较麻烦,也不利于分析。Netflix提供了一个可以聚合多个应用的监控信息的工具,叫turbine。使用turbine时,一般会独立一个工程,在pom.xml中添加如下依赖。

<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-turbine</artifactId>
</dependency>

turbine在聚合多个应用实例的监控信息是通过Eureka进行实例发现的,所以它本身将作为一个Eureka Client,还需要往pom.xml中添加Eureka Client的依赖。

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

使用turbine的工程的配置类上需要加上@EnableHystrixDashboard启用Hystrix Dashboard,加上@EnableTurbine启用turbine支持。而此时被聚合的应用可以不再启用Hystrix Dashboard。

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

使用turbine还需要进行一些配置,如下配置指定了Eureka Server的地址,且当前应用不需要向Eureka Server进行注册。turbine.appConfig指定了需要聚合的应用,对应于向Eureka Server注册的serviceId,即spring.application.name指定的值,下面的配置指定的需要聚合的服务是spring1。turbine.aggregator.clusterConfig指定了集群的名称,集群的名称只是用来把turbine.appConfig配置的服务名称分个组,默认是服务名称的大写形式,所以我们这里配置为SPRING1。

eureka.client.serviceUrl.defaultZone=http://localhost:8089/eureka/
eureka.client.registerWithEureka=false
server.port=9000

turbine.appConfig=spring1
turbine.aggregator.clusterConfig=SPRING1

turbine.appConfigturbine.aggregator.clusterConfig需要指定成一样的。

服务启动后,就可以通过/turbine.stream?cluster=SPRING1访问到类似如下这样收集到的群集SPRING1的信息。

turbine stream

hystrix.stream一样,上面收集到的信息是JSON格式,不直观。我们也可以在Hystrix Dashboard中查看对应的图形界面信息。通过访问/hystrix进入Hystrix Dashboard的首页,在输入监控地址的位置输入http://localhost:9000/turbine.stream?cluster=SPRING1,然后点击Monitor Stream按钮进入监控页面,你会看到类似如下这样的界面。

turbine stream dashboard

turbine也可以同时监控多个不同的服务,监控多个不同的服务时,多个不同的服务之间以英文的逗号分隔,集群名称之间也是以英文逗号分隔。比如下面的配置,可以通过集群SPRING1监控服务spring1的相关信息,通过集群SPRING2监控服务spring2的相关信息。

turbine.appConfig=spring1,spring2
turbine.aggregator.clusterConfig=SPRING1,SPRING2

当一个turbine中同时指定了多个集群信息时,可以通过/clusters查看定义好的集群信息。基于上面的配置信息访问http://localhost:9000/clusters可以看到如下信息。

cluster info

当使用的集群名称是default时,访问turbine.stream可以不指定cluster。可以通过下面的配置指定cluster名称为default。下面的配置相当于指定了服务spring1和spring2的集群名称都是default,在监控的时候可以同时监控这两个服务的相关信息。

turbine.appConfig=spring1,spring2
turbine.clusterNameExpression="default"

如果是基于YAML配置,需要指定turbine.clusterNameExpression的值为"'default'"

(注:本文是基于Spring cloud Finchley.SR1所写)

0
0
分享到:
评论

相关推荐

    spring-cloud-hystrix-dashboard(包含注册中心、member、hystrix-dashboard配置等).zip

    spring-cloud-hystrix-dashboard(包含注册中心、member、hystrix-dashboard配置等).zip 包含配置好的eureka注册中心,member服务生产者、hystrix-dashboard的hystrix配置和仪表盘配置

    springcloud2-hystrix-feign-zuul.zip

    标题 "springcloud2-hystrix-feign-zuul.zip" 提示了我们这是一组关于Spring Cloud 2的实现,具体涉及Hystrix、Feign和Zuul组件的实践项目。Spring Cloud 是一个用于构建分布式系统的服务发现、配置管理和微服务连接...

    15.Spring Cloud中使用Hystrix

    在Spring Cloud生态系统中,Hystrix是一个至关重要的组件,它主要负责实现服务容错和断路器模式,以增强系统的稳定性和健壮性。本文将深入探讨如何在Spring Cloud项目中集成并使用Hystrix,以及如何将其与Feign...

    spring cloud hystrix &&dashboard源码解读

    ### Spring Cloud Hystrix & Dashboard 源码解读 #### 一、加载、初始化概要 ##### 1.1 @EnableCircuitBreaker 的生效 `@EnableCircuitBreaker` 注解是 Spring Cloud Hystrix 提供的一个关键注解,用于启动熔断器...

    SpringCloud10-2 Hystrix整合Dashboard教程

    在本教程中,我们将深入探讨如何在Spring Cloud项目中整合Hystrix Dashboard,这是一个强大的工具,用于监控微服务架构中的断路器性能。Hystrix是Netflix开源的一个库,它为分布式系统提供了延迟和容错的基础设施,...

    SpringCloud10-Hystrix熔断器及服务熔断

    为了提高系统的稳定性和容错性,Spring Cloud引入了Hystrix组件,这是一个强大的断路器库,用于防止服务雪崩效应。本文将深入探讨Spring Cloud中的Hystrix熔断器以及服务熔断机制。 首先,理解什么是熔断器模式至关...

    SpringCloud之熔断监控Hystrix Dashboard的实现

    SpringCloud之熔断监控Hystrix Dashboard的实现 SpringCloud 是微服务中的翘楚,最佳的落地方案。SpringCloud 中的 Hystrix 组件可以实现熔断,而在实际情况中,一般还需要直观地看到各个服务的调用情况,这时,就...

    spring-cloud-netflix-hystrix-dashboard-2.2.3.RELEASE.jar

    spring-cloud-netflix-hystrix-dashboard-2.2.3.RELEASE.jar

    springcloud 熔断监控Hystrix Dashboard和Turbine

    总结起来,SpringCloud的Hystrix Dashboard和Turbine是微服务架构中重要的监控和容错管理组件。Hystrix Dashboard用于单个应用的实时监控,而Turbine则负责聚合多个服务的监控信息,提供全局视图。这两个工具的使用...

    springcloud feign整合hystrix(服务降级).doc

    在Spring Cloud微服务架构中,Feign和Hystrix是两个重要的组件,它们协同工作以实现服务间的调用和容错处理。Feign是一个声明式的Web服务客户端,它使得编写Web服务客户端变得简单,而Hystrix则是一个用于处理延迟和...

    SpringCloud10-Hystrix熔断器学习代码及指定默认的全局兜底方法

    这个标题"SpringCloud10-Hystrix熔断器学习代码及指定默认的全局兜底方法"揭示了我们要讨论的主题——如何使用Hystrix进行熔断操作,并配置全局的 fallback 方法来处理服务调用失败的情况。 Hystrix的工作原理基于...

    hystrix-dashboard.zip

    【标题】"hystrix-dashboard.zip" 是一个包含示例代码的压缩包,与Spring Cloud相关的Hystrix Dashboard集成有关。Hystrix Dashboard是Netflix开源的一款监控工具,它能够帮助我们实时监控微服务架构中的断路器状态...

    springcloud hystrix 断路由

    在分布式系统中,服务间的调用异常处理是至关重要的,Spring Cloud Hystrix 就是为了解决这一问题而设计的。Hystrix 是 Netflix 开源的一个延迟和容错库,用于隔离服务间的调用,防止因某个服务的不稳定导致整个系统...

    spring-cloud-netflix-hystrix应用

    《深入理解Spring Cloud Netflix Hystrix:构建弹性微服务架构》 在当今的软件开发领域,微服务架构已经成为主流,而Spring Cloud作为Java生态中的微服务解决方案,深受开发者喜爱。其中,Spring Cloud Netflix ...

    Hystrix Dashboard的使用-代码部分.zip

    2. **Turbine 配置**: 配置 Turbine 应指定如何发现服务实例,通常使用 Eureka 或者 Spring Cloud Config 来动态获取服务列表。 3. **动态聚合**: Turbine 支持动态聚合,这意味着当新的服务实例加入或离开时,无需...

    Spring Cloud(Hystrix)使用.zip

    本教程将通过分析`microservice-hystrix-dashboard`、`microservice-client`和`microservice-springcloud`这三个项目来深入理解Spring Cloud Hystrix的使用。 首先,`microservice-hystrix-dashboard`是Hystrix的...

    SpringCloud Hystrix-Dashboard仪表盘的实现

    SpringCloud Hystrix-Dashboard 仪表盘的实现 SpringCloud Hystrix-Dashboard 仪表盘是 SpringCloud 中的一种监控工具,它可以实时监控 Hystrix 的各项指标信息。通过 Hystrix Dashboard 反馈的实时信息,可以帮助...

    springcloud教程源码 springcloud demo

    课程中对比了 Dubbo 和 SpringCloud,并深入讲授SpringCloud核心组件Eureka、Ribbon、Feign、Hystrix、HystrixDashboard、Zuul、Config。除此之外,还通过整合SpringMVC+SpringBoot+Mybatis构建一个可用的基于Spring...

    hystrix-dashboard-1.5.9.war

    springcloud hystrix-dashboard

Global site tag (gtag.js) - Google Analytics