SpringCloud Hystrix-Dashboard仪表盘的实现
作者:寻找风口的猪 发布时间:2023-03-16 18:38:03
Hystrix Dashboard,它主要用来实时监控Hystrix的各项指标信息。通过Hystrix Dashboard反馈的实时信息,可以帮助我们快速发现系统中存在的问题。下面通过一个例子来学习。
一、新建一个Spring Cloud 项目,命名为hystrix-dashboard
1.1在pom.xml引入相关的依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
1.2在spring boot 的启动类上面引入注解@EnableHystrixDashboard,启用Hystrix Dashboard功能。
package org.hope.hystrix.dashboard;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@EnableHystrixDashboard
@SpringCloudApplication
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
1.3修改配置文件application.properties
spring.application.name=hystrix-dashboard
server.port=2001
1.4启动应用,然后再浏览器中输入http://localhost:2001/hystrix可以看到如下界面
通过Hystrix Dashboard主页面的文字介绍,我们可以知道,Hystrix Dashboard共支持三种不同的监控方式
☞默认的集群监控:通过URL:http://turbine-hostname:port/turbine.stream开启,实现对默认集群的监控。
☞指定的集群监控:通过URL:http://turbine-hostname:port/turbine.stream?cluster=[clusterName]开启,实现对clusterName集群的监控。
☞单体应用的监控:通过URL:http://hystrix-app:port/hystrix.stream开启,实现对具体某个服务实例的监控。
☞Delay:控制服务器上轮询监控信息的延迟时间,默认为2000毫秒,可以通过配置该属性来降低客户端的网络和CPU消耗。
☞Title:该参数可以展示合适的标题。
二、要有一个eureka-server用来提供eureka的服务注册中心,在码云上有,可以作为参考。此处不再粘代码。
三、要有一个eureka-service来提供服务,工程名为hello-service,项目地址同上。
四、新建一个服务被监控的工程,工程名为ribbon-customer。
4.1pom.xml引入相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
4.2在启动类上添加@EnableCircuitBreaker 开启断路器功能
package com.didispace;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@EnableCircuitBreaker //开启断路器功能
@EnableDiscoveryClient
@SpringBootApplication
public class ConsumerApplication {
@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class, args);
}
}
4.3 RestController
package com.didispace.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ConsumerController {
@Autowired
HelloService helloService;
@RequestMapping(value = "/ribbon-consumer", method = RequestMethod.GET)
public String helloConsumer() {
return helloService.hello();
}
}
4.4 application.properties配置文件
spring.application.name=ribbon-consumer
server.port=9000
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000
通过上面的步骤,已经基本完成了准备工作,下面我们进行测试。
1.启动eureka-server
2.启动hello-service
3.启动ribbon-customer
4.启动hystrix-dashboard
5.在浏览器输入http://localhost:2001/hystrix
6.在浏览器的新窗口输入http://localhost:9000/ribbon-consumer
7.在Hystrix-Dashboard的主界面上输入: http://localhost:9000/hystrix.stream然后点击 Monitor Stream按钮
在监控的界面有两个重要的图形信息:一个实心圆和一条曲线。
实心圆:1、通过颜色的变化代表了实例的健康程度,健康程度从绿色、黄色、橙色、红色递减。2、通过大小表示请求流量发生变化,流量越大该实心圆就越大。所以可以在大量的实例中快速发现故障实例和高压实例。
曲线:用来记录2分钟内流浪的相对变化,可以通过它来观察流量的上升和下降趋势。
注意:当使用Hystrix Board来监控Spring Cloud Zuul构建的API网关时,Thread Pool信息会一直处于Loading状态。这是由于Zuul默认会使用信号量来实现隔离,只有通过Hystrix配置把隔离机制改成为线程池的方式才能够得以展示。
参考:
[1]《Spring Cloud微服务实战》,翟永超
[2]博客,纯洁的微笑,https://www.jb51.net/article/167053.htm
来源:https://www.cnblogs.com/happyflyingpig/p/8372485.html


猜你喜欢
- 一、什么是锁擦除锁擦除是指虚拟机即时编译器(JIT)在运行时,对一些代码上要求同步,但是被检测到不可能存在共享数据竞争的锁进行擦除。锁擦除的
- 本文实例为大家分享了Android日历控件的使用方法,供大家参考,具体内容如下MainActivity.java代码:package sis
- 本文实例讲述了Android开发中使用颜色矩阵改变图片颜色,透明度及亮度的方法。分享给大家供大家参考,具体如下:一、如图二、代码实现publ
- 昨晚,一同事问到我,怎么利用java反射解析内部类静态成员变量的值,于是顺手写下了。废话不多说,直接上代码!待解析类结构如下:/** * @
- 本文实例讲述了C#实现在前端网页弹出警告对话框(alert)的方法。分享给大家供大家参考。具体如下:通常我们通过JS生成警告对话框,下面的代
- 从相册或拍照更换图片功能的实现:(取图无裁剪功能)获取图片方式: (类似更换头像的效果)1、手机拍照 选择图片;2、相册选取图片;本文只是简
- String ipArr[]={"127.0.0.1","127.0.0.2"}; &n
- 最近上线的项目中数据库数据已经临近饱和,最大的一张表数据已经接近3000W,百万数据的表也有几张,项目要求读数据(select)时间不能超过
- 1.项目介绍这是一款基于 Java 开发的移动端安卓小游戏——大家来拼图2.项目原理把选定的一张图片
- 目录开始准备开始动画画圆弧项目使用背景图完整代码今天介绍一个很简单的倒计时动画,仿酷狗音乐的启动页倒计时效果,也是大多数APP在用的一个动画
- 动手写一个java版简单云相册,实现的功能是: 用户可以一次上传一个至多个文件。 用户可以下载其他人上传的图片。 用户可以查看其他所有人的图
- 实现Callable的对象中,用@Autowired注入别的对象失败场景是这样:我需要在一个实现类A中写一个拿到返回值的多线程,于是用的Ca
- 目录通过切面,实现超灵活的注解式数据校验Spring MVC的校验方式通过切面实现自己的注解式数据校验Spring boot aop注解数据
- 本文实例为大家分享了Android屏幕适配工具类的具体代码,供大家参考,具体内容如下DimenToolgithub地址Android 屏幕适
- 一、什么是桥接模式:桥接,顾名思义,就是用来连接两个部分,使得两个部分可以互相通讯,桥接模式的作用就是为被分离的抽象部分和实现部分搭桥。在现
- 最近在搞一个购物车的功能,里面有一个批量删除的操作,采用的是ExpandableListView以及BaseExpandableListAd
- 自动完成文本框(AutoCompleteTextView),用于实现允许用户输入一定字符后,显示一个下拉菜单,供用户从中选择,当用户选择某个
- 实现效果如下:实现思路:1、如何实现圆中水面上涨效果:利用Paint的setXfermode属性为PorterDuff.Mode.SRC_I
- 场景做一个消息中心,专门负责发送消息。消息分为几种渠道,包括手机通知(Push)、短信(SMS)、邮件(Email),Websocket等渠
- 好久没有写有关UI的博客了,刚刚翻了一下之前的博客,最近一篇有关UI的博客:Android UI设计系列之自定义Dialog实现各种风格的对