Hystrix Dashboard断路监控仪表盘的实现详细介绍
作者:悠然予夏 发布时间:2022-07-29 05:27:26
正常状态是UP,跳闸是⼀种状态CIRCUIT_OPEN,可以通过/health查看,前提是工程中需要引入SpringBoot的actuator(健康监控),它提供了很多监控所需的接口,可以对应用系统进行配置查看、相关功能统计等。
已经统一添加在父工程中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
如果我们想看到Hystrix相关数据,比如有多少请求、多少成功、多少失败、多少降级等,那么引入SpringBoot健康监控之后,访问/actuator/hystrix.stream接口可以获取到监控的文字信息,但是不直观,所以Hystrix官方还提供了基于图形化的DashBoard(仪表板)监控平 台。Hystrix仪表板可以显示每个断路器(被@HystrixCommand注解的方法)的状态。
1)新建一个监控服务工程,导入依赖
<?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">
<parent>
<artifactId>lagou-parent</artifactId>
<groupId>com.lagou</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>lagou-cloud-hystrix-dashboard-9000</artifactId>
<dependencies><!--hystrix-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!--hystrix 仪表盘-->
<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-eureka-client</artifactId>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
2)启动类添加@EnableHystrixDashboard激活仪表盘
package com.lagou.edu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@SpringBootApplication
@EnableHystrixDashboard // 开启hystrix dashboard
public class HystrixDashboardApplication9000 {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication9000.class, args);
}
}
3) application.yml
server:
port: 9000
Spring:
application:
name: lagou-cloud-hystrix-dashboard
eureka:
client:
serviceUrl: # eureka server的路径
defaultZone: http://LagouCloudEurekaServerB:8762/eureka,http://LagouCloudEurekaServerA:8761/eureka #把 eureka 集群中的所有 url 都填写了进来,也可以只写⼀台,因为各个 eureka server 可以同步注册表
instance:
#使⽤ip注册,否则会使⽤主机名注册了(此处考虑到对⽼版本的兼容,新版本经过实验都是ip)
prefer-ip-address: true
#⾃定义实例显示格式,加上版本号,便于多版本管理,注意是ip-address,早期版本是ipAddress
instance-id: ${spring.cloud.client.ipaddress}:${spring.application.name}:${server.port}:@project.version@
4)在被监测的微服务中注册监控servlet(自动投递微服务,监控数据就是来自于这个微服务)
package com.lagou.edu;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableDiscoveryClient
// @EnableHystrix // 打开Hystrix功能
@EnableCircuitBreaker // 开启熔断器功能(这个与@EnableHystrix的功能相同,只不过它是通用注解)
// @SpringCloudApplication // 综合性注解 @SpringCloudApplication = @SpringBootApplication + @EnableDiscoveryClient + @EnableCircuitBreaker
public class AutoDeliverApplication {
public static void main(String[] args) {
SpringApplication.run(AutoDeliverApplication.class, args);
}
// 使用RestTemplate模板对象远程调用
@Bean
@LoadBalanced
public RestTemplate gerRestTemplate() {
return new RestTemplate();
}
/**
* 给被监控微服务中注册一个servlet,后期我们就是通过访问这个servlet来获取服务的Hystrix监控数据的
* 前提:被监控的微服务,需要引入SpringBoot Actuator的功能
* @return
*/
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}
被监控微服务发布之后,可以直接访问监控servlet,但是得到的数据并不直观,后期可以结合仪表盘更友好的展示
5)访问测试http://localhost:9000/hystrix
输入监控的微服务端点地址,展示监控的详细数据,比如监控服务消费者http://localhost:8090/actuator/hystrix.stream
实心圆:
大小:代表请求流量的大小,流量越大球越大颜色:代表请求处理的健康状态,从绿色到红色递减,绿色代表健康,红色就代表很不健康
曲线波动图:记录了2分钟内该方法上流量的变化波动图,判断流量上升或者下降的趋势
来源:https://blog.csdn.net/weixin_52851967/article/details/126455020


猜你喜欢
- 自定义TypeHandler映射JSON类型为List1. 实体类这里只展示需要映射的字段,分别在所需映射的字段和实体类上添加注解。&nbs
- 本文中我将介绍一下我自己封装的一个小的工具类库:按钮点击事件类库。作用:该类库可以防止按钮重复点击,可以判断网络状态,可以判断用户登录状态,
- 自定义对象作为HashMap的Key这个问题在很多面试者面试时都会被提及,本人也是最近在看effective java第九条:覆盖equal
- 概述由于微信公众平台的特殊机制,所有的信息都由微信服务器转发而来,因此服务器是无法使用Session对用户会话的上下文进行管理的。为此Sen
- 本文主要是对Handler和消息循环的实现原理进行源码分析,如果不熟悉Handler可以参见博文《详解Android中Handler的使用方
- 本文演示android中图片加载到内存首先设计界面:代码如下:<LinearLayout xmlns:android="ht
- WPF下给ComboBox设置绑定字段时可通过如下设置:combobox.SelectedValuePath = "编号"
- 记录Java执行groovy脚本的两种方式,简单粗暴:一种是通过脚本引擎ScriptEngine提供的eval(String)方法执行脚本内
- 1. 概述官方JavaDocsApi: javax.swing.JTextAreaJTextArea,文本区域。JTextArea 用来编辑
- 安装hbase首先下载hbase的最新稳定版本 http://www.apache.org/dyn/closer.cgi/hbas
- APP中可能会遇到一种需求,就是将当前所在位置的坐标传到服务器上,今天我提供三种途径去获取经纬度坐标信息,第一种是通过Android API
- 今天闲来无事写了一个清内存的小东西,类似360,在桌面上悬浮,点击后清除后台无用程序,清除后台程序是通过调用ActivityManger.k
- 本文基于jdk1.8进行分析关于HashMap的简介,可以参考这篇文章https://www.jb51.net/article/154177
- 本文实例为大家分享了Android仿抖音列表效果的具体代码,供大家参考,具体内容如下当下抖音非常火热,是不是也很心动做一个类似的app吗?那
- 背景Java是一种流行的编程语言,验证码是一种常用的网络安全技术。Java发展至今,网上也出现了各种各样的验证码,本人初学Java,下面是我
- 今天是圣诞节平安夜,为此特别制作了一个雪花飘落的场景,我们的雪花渲染方式不同于网上流行的使用Camera Filter,需要将脚本挂接到相机
- 在我们做项目的过程中,有可能会遇到跨域请求,所以需要我们自己组装支持跨域请求的JSONP数据,而在4.1版本以后的SpringMVC中,为我
- 一.背景项目中有个需求大体意思是,上传一个word模板,根据word模板合成word文件,再将word文件转为pdf。二.方案选择1.Spi
- 大家可能在做app的时候,或多或少需要使用联系人,而根据google提供的api,你需要编写大量的代码,例如首先需要查询数据库,涉及到数据库
- mybatis的foreach标签经常用于遍历集合,构建in条件语句或者批量操作语句。下面是foreach标签的各个属性属性描述collec