首页 > 其他分享 >Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard

时间:2023-08-14 17:04:13浏览次数:34  
标签:hystrix Hystrix Spring springframework Cloud spring sc org cloud


 

       上一篇【Spring Cloud 2.x系列之如何使用断路器监控Hystrix Dashboard】只是大概介绍了一下断路器HystrixDashboard监控,如何使用HystrixDashboard监控微服务的状态呢?这篇看看Ribbon如何整合断路器监控Hystrix Dashboard。今天的项目主要整合sc-eureka-client-consumer-ribbon-hystrix项目【Spring Cloud 2.x系列之RestTemplate+Ribbon整合断路器Hystrix】和sc-hystrix-dashboard项目【Spring Cloud 2.x系列之如何使用断路器监控Hystrix Dashboard

 

1、        新建项目sc-ribbon-hystrix-dashboard,对应的pom.xml文件

 

<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>


  <groupId>spring-cloud</groupId>

  <artifactId>sc-ribbon-hystrix-dashboard</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>jar</packaging>


  <parent>

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-parent</artifactId>

      <version>2.0.4.RELEASE</version>

   </parent>


   <dependencyManagement>

      <dependencies>

        <dependency>

           <groupId>org.springframework.cloud</groupId>

           <artifactId>spring-cloud-dependencies</artifactId>

           <version>Finchley.RELEASE</version>

           <type>pom</type>

           <scope>import</scope>

        </dependency>


      </dependencies>

   </dependencyManagement>



   <properties>

      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

      <maven.compiler.source>1.8</maven.compiler.source>

      <maven.compiler.target>1.8</maven.compiler.target>

   </properties>


   <dependencies>

      <dependency>

        <groupId>org.springframework.cloud</groupId>

         <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

      </dependency>

      <!-- <dependency>

           <groupId>org.springframework.cloud</groupId>

           <artifactId>spring-cloud-starter-ribbon</artifactId>

           <version>1.4.5.RELEASE</version>

        </dependency>-->


      <dependency>

        <groupId>org.springframework.cloud</groupId>

        <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
      </dependency>

      <dependency>

          <groupId>org.springframework.boot</groupId>

          <artifactId>spring-boot-starter-web</artifactId>

      </dependency>


      <!--    

      <dependency>

         <groupId>org.springframework.cloud</groupId>

          <artifactId>spring-cloud-starter-hystrix</artifactId>

         <version>1.4.5.RELEASE</version>

      </dependency>-->

      <dependency>

          <groupId>org.springframework.cloud</groupId>

          <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>

      </dependency>

      <!-- <dependency>

         <groupId>org.springframework.cloud</groupId>

          <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>

         <version>1.4.5.RELEASE</version>

      </dependency>-->

      <dependency>

          <groupId>org.springframework.cloud</groupId>

          <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>

      </dependency>

      <dependency>

          <groupId>org.springframework.boot</groupId>

          <artifactId>spring-boot-starter-actuator</artifactId>

      </dependency>


   </dependencies>

</project>

 

可以看到这个pom.xml文件是sc-eureka-client-consumer-ribbon-hstrix项目【Spring Cloud 2.x系列之RestTemplate+Ribbon整合断路器Hystrix】和sc-hystrix-dashboard项目【Spring Cloud 2.x系列之如何使用断路器监控Hystrix Dashboard】的pom.xml的并集

 

 

2、        新建spring boot 启动类HystrixDashboardApplication.java

package sc.consumer;



import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

import org.springframework.cloud.netflix.hystrix.EnableHystrix;

import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;



@SpringBootApplication

@EnableEurekaClient

@EnableHystrix

@EnableHystrixDashboard

public class HystrixDashboardApplication {

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


}



}

可以看到这个启动类的注解也是sc-eureka-client-consumer-ribbon-hstrix项目【Spring Cloud 2.x系列之RestTemplate+Ribbon整合断路器Hystrix】和sc-hystrix-dashboard项目【Spring Cloud 2.x系列之如何使用断路器监控Hystrix Dashboard】的启动类的并集

 

3、        其他的java类就不多说了,项目接口如下

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_eureka

 

4、        分别启动配置中心sc-eureka-server【Spring Cloud 2.x系列之eureka注册中心单机】和服务提供者sc-eureka-client-provider【Spring Cloud 2.x系列之服务注册&服务提供者】 

5、        启动项目sc-ribbon-hystrix-dashboard

方式一:http://127.0.0.1:5600/hystrix验证是否启动成功

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_微软_02

       方式二:访问http://127.0.0.1:5600/hystrix.stream

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_微软_03

这个是访问DashboardServletConfig.java这个servlet对应的地址。

     上篇说了一下下图这段英文的大概意思

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_zookeeper_04

6、        演示一下单应用模式下的断路器监控Hystrix Dashboard 在url里输入

http://127.0.0.1:5600/hystrix.stream(IP和端口对应服务消费者的IP和端口)

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_ribbon_05

然后点击Monitor Stream按钮

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_ribbon_06

7、        使用postman访问任何接口,以获取用户列表为例(http://127.0.0.1:5600/cli/user/listUser),多访问几次在查看对应的监控界面

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_maven_07

发现监控界面的图出现了动态变化,这个就是对服务调用的监控。图中相关单元的含义可以查看:

https://github.com/Netflix-Skunkworks/hystrix-dashboard/wiki

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_maven_08

http://127.0.0.1:5600/hystrix.stream对应的界面也出现了大量数据,这个也是对服务调用监控的数据。

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_ribbon_09

其他接口也自行测试。

 

源码:

https://gitee.com/hjj520/spring-cloud-2.x/tree/master/sc-ribbon-hystrix-dashboard

 


关注「Java乐园」,做全栈开发工程师

Spring Cloud 2.x系列之Ribbon整合断路器监控Hystrix Dashboard_微软_10

标签:hystrix,Hystrix,Spring,springframework,Cloud,spring,sc,org,cloud
From: https://blog.51cto.com/u_13538361/7078659

相关文章

  • 【maven】spring-boot-configuration-processor依赖
     依赖:<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency>作用:生成配置元数据。(给自定义的配置类生成元数据信......
  • SAP Commerce Cloud 中的 SimpleResponsiveBannerComponent
    SAPCommerceCloud(以下简称SAPCC)是一款综合性的电子商务解决方案,旨在帮助企业建立和管理现代化的电子商务平台。SimpleResponsiveBannerComponent是SAPCC中的一个核心组件,专门用于管理和展示响应式横幅广告。它允许商户轻松地在其电子商务平台上添加、配置和管理各种横幅......
  • 【Spring Cloud 】智慧建筑工地平台源码
    智慧工地源码智慧工地云平台源码智慧建筑源码支持私有化部署,提供SaaS+硬件设备+运维全套服务互联网+建筑工地,是将互联网+的理念和技术引入建筑工地,从施工现场源头抓起,最大程度的收集人员、安全、环境、材料等关键业务数据,依托物联网、互联网,建立云端大数据管理平台,形成“端+云+......
  • springboot开启prometheus可采集的指标配置
    1、引包<!--实现对Actuator的自动化配置--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>......
  • SpringBoot实现大文件上传
    ​ 对于大文件的处理,无论是用户端还是服务端,如果一次性进行读取发送、接收都是不可取,很容易导致内存问题。所以对于大文件上传,采用切块分段上传,从上传的效率来看,利用多线程并发上传能够达到最大效率。 本文是基于springboot+vue实现的文件上传,本文主要介绍服务端实现文件......
  • 认识Spring AOP 面向切面编程
    一.什么是SpringAOP关于什么是SpringAOP.当我翻到官方文档的时候也是一惊LetusbeginbydefiningsomecentralAOPconceptsandterminology.ThesetermsarenotSpring-specific…unfortunately,AOPterminologyisnotparticularlyintuitive;however,itwoul......
  • Spring 响应式编程-读书笔记
    本文为《Spring响应式编程》的读书笔记,响应式技术栈可以创建极其高效、易于获取且具有回弹性的端点,同时响应式可以容忍网络延迟,并以影响较小的方式处理故障。响应式微服务还可以隔离慢速事务并加速速度最快的事务。通过本书可以学到以下内容:响应式编程基本原则和响应式流(Reactive......
  • Spring Cloud之网关
    接口的分类:开放接口:可以授权一些接口口OAuth2.0协议方式第三方联合登录内部接口:一般只能在局域网中进行访问,服务与服务之间关系都在同一个微服务系统中。目的是为了保证安全问题接口设计:接口权限开放or内部幂等性安全性https防止篡改数据(验证签名)网关拦截接口实......
  • Spring Cloud Alibaba-服务雪崩效应
    一、高并发带来的问题在微服务架构中,我们将业务拆分成一个个的服务,服务与服务之间可以相互调用,但是由于网络原因或者自身的原因,服务并不能保证服务的100%可用,如果单个服务出现问题,调用这个服务就会出现网络延迟,此时若有大量的网络涌入,会形成任务堆积,最终导致服务瘫痪。二、服务......
  • 使用Spring initializr快速创建一个springboot项目
     第一步首先new一个新的project选择Springinitializr配置好相关信息后下一步编辑在左上角我们可以选择SprinBoot的版本,在这里直接加入web依赖springweb和Template的Thymeleaf依赖,点上对勾后可以在最右边里看到你选择的依赖,然后点击create编辑可以看到我们的项目结构,很多sprin......