第九篇: 断路器监控(Hystrix Dashboard)

第三篇:断路器(Hystrix)讲述了如何使用断路器,并简单的介绍了下Hystrix Dashboard组件,这篇文章更加详细的介绍Hystrix Dashboard。

一、Hystrix Dashboard简介

在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。

二、准备工作

本文的的工程栗子,来源于第一篇: 服务的注册 内的 eureka服务第二篇: 服务消费者(Feign)内的feign服务为引用,在它的基础上进行改造。

三、开始改造 leopard-service-feign

在pom的工程文件引入相应的依赖(必须):

		<!-- 监控 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<!-- hystrix 依赖 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix</artifactId>
		</dependency>
		<!-- hystrix web 视图查看 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
		</dependency>

在程序的入口FeignServiceApplication类,加上@EnableHystrix注解开启断路器,这个是必须的,并且需要在程序中声明断路点HystrixCommand;加上@EnableHystrixDashboard注解,开启HystrixDashboard

package com.leopard.service.feign;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
 
@EnableDiscoveryClient
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
@EnableHystrix
@EnableHystrixDashboard
public class FeignServiceApplication {
 
	public static void main(String[] args) {
		SpringApplication.run(FeignServiceApplication.class, args);
	}
}

运行程序: 依次开启 leopard-eureka 和 leopard-service-feign.

四、Hystrix Dashboard图形展示

打开 http://localhost:8181/hystrix.stream,可以看到一些具体的数据:

打开http://localhost:8181/hystrix 可以看见以下界面:

并依次输入  http://localhost:8181/hystrix.stream 、2000 、service-feign

确认后可以看到如下界面:

这个时候,再打开一个新窗口,访问 http://localhost:8181/test/getPort     ,可以看到

此时回到,上一个窗口可以看到

再回到上上层,一开始 打开的 http://localhost:8181/hystrix.stream 页面,可以看到已经加载到数据的监控页面信息:

到此就完成了监控搭建。

文章转载:https://blog.csdn.net/forezp/article/details/70217283

文章参考:

https://www.cnblogs.com/chenweida/p/9025589.html

https://blog.csdn.net/qiuqiangqiang/article/details/80273091

猜你喜欢

转载自blog.csdn.net/u014799292/article/details/84235397
今日推荐