14、Ribbon整合断路器监控Hystrix Dashboard

公众号: java乐园

上一篇只是大概介绍了一下断路器Hystrix Dashboard监控,如何使用Hystrix Dashboard监控微服务的状态呢?这篇看看Ribbon如何整合断路器监控Hystrix Dashboard。今天的项目主要整合sc-eureka-client-consumer-ribbon-hystrix项目和sc-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.0 http://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项目和sc-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项目和sc-hystrix-dashboard项目的启动类的并集

3、 其他的java类就不多说了,项目接口如下
在这里插入图片描述

4、 分别启动配置中心和sc-eureka-server和服务提供者sc-eureka-client-provider

5、 启动项目sc-ribbon-hystrix-dashboard
方式一:http://127.0.0.1:5600/hystrix验证是否启动成功
在这里插入图片描述
方式二:访问http://127.0.0.1:5600/hystrix.stream
在这里插入图片描述
这个是访问DashboardServletConfig.java这个servlet对应的地址
上篇说了一下下图这段英文的大概意思
在这里插入图片描述
6、 演示一下单应用模式下的断路器监控Hystrix Dashboard
在url里输入:http://127.0.0.1:5600/hystrix.stream(IP和端口对应服务消费者的IP和端口)
在这里插入图片描述
然后点击Monitor Stream按钮
在这里插入图片描述
7、 使用postman访问任何接口,以获取用户列表为例(http://127.0.0.1:5600/cli/user/listUser),多访问几次在查看对应的监控界面
在这里插入图片描述
发现监控界面的图出现了动态变化,这个就是对服务调用的监控。图中相关单元的含义可以查看:
https://github.com/Netflix-Skunkworks/hystrix-dashboard/wiki
在这里插入图片描述
http://127.0.0.1:5600/hystrix.stream对应的界面也出现了大量数据,这个也是对服务调用监控的数据。
在这里插入图片描述
其他接口也自行测试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BUG弄潮儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值