13、如何使用断路器监控Hystrix Dashboard

简介: Hystrix Dashboard作为断路器监控的一个重要组件,提供了数据监控及非常友好的图形化界面,方便运维人员对服务进行监控;,通过界面反馈的信息可以快速发现系统中存在的问题。另外Hystrix Dashboard是一个独立的服务结点,不需要配置任何的注册中心。

在微服务架构中如何去监控服务的状态是否正常,非常重要。为例保证微服务的可用性,防止程序断路器模型。运维人员需要一个友好的程序来监控微服务的状态, Hystrix Dashboard作为断路器监控的一个重要组件,提供了数据监控及非常友好的图形化界面,方便运维人员对服务进行监控;,通过界面反馈的信息可以快速发现系统中存在的问题。另外Hystrix Dashboard是一个独立的服务结点,不需要配置任何的注册中心。

 

1、 新建项目sc-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-hystrix-dashboard</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>sc-hystrix-dashboard</name>
  <url>http://maven.apache.org</url>
  <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-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.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.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  </dependencies>
</project>


说明:spring cloud 2.x之后spring-cloud-starter-hystrix-dashboard和spring-cloud-starter-hystrix都标志为过期,具体推荐使用两个依赖请看下面的图片


微信图片_20220501180056.png


微信图片_20220501180101.png


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


package sc.hystrix.dashboard;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@SpringBootApplication
@EnableHystrixDashboard
public class DashboardApplication {
public static void main(String[] args) {
SpringApplication.run(DashboardApplication.class, args);
}
}


只需添加注解EnableHystrixDashboard,启动Hystrix Dashboard即可

 

3、 配置Hystrix Dashboard对应的Servlet


package sc.hystrix.dashboard;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
@Configuration
public class DashboardServletConfig {
@Bean
public ServletRegistrationBean getDashboardServlet(){
HystrixMetricsStreamServlet servlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean bean = new ServletRegistrationBean(servlet);
bean.setLoadOnStartup(1);
bean.addUrlMappings("/hystrix.stream");
bean.setName("hystrix");
return bean;
}
}


4、 新建配置文件bootstrap.yml


spring:
  application:
    name: sc-hystrix-dashboard
server:
  port: 2001


5、 启动并验证是否启动成功


方法一:查看日志配置的端口2001,在日志中标志启动成功


微信图片_20220501180108.png


方法二:从上图标志的1中可以知道可以方法地址:http://127.0.0.1:2001/hystrix


微信图片_20220501180113.png

 

6、 分析一下下图中的英文


微信图片_20220501180117.png

 

大概的意思是:如果查看默认集群使用第一个url查看指定集群使用第二个url单个应用监控使用最后一个

 

7、 url中输入http://127.0.0.1:2001/hystrix.stream


微信图片_20220501180122.png

 

然后点击Monitor Stream按钮


微信图片_20220501180126.png

 

或者访问http://localhost:2001/hystrix.stream也会不断的显示ping


微信图片_20220501180130.png

 




相关文章
|
5月前
|
Cloud Native Go 微服务
golang 微服务中的断路器 hystrix
golang 微服务中的断路器 hystrix
|
1月前
|
监控 微服务
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
17 0
|
4月前
|
监控 负载均衡 数据可视化
SpringCloud - Hystrix断路器-服务熔断与降级和HystrixDashboard
SpringCloud - Hystrix断路器-服务熔断与降级和HystrixDashboard
28 0
|
5月前
|
Cloud Native 测试技术 Go
golang 微服务中的断路器 hystrix 小案例
golang 微服务中的断路器 hystrix 小案例
|
6月前
|
监控 Java 微服务
16SpringCloud - 断路器项目示例(Hystrix Dashboard)
16SpringCloud - 断路器项目示例(Hystrix Dashboard)
24 0
|
6月前
|
Java Spring
15SpringCloud - 断路器项目示例(Feign Hystrix)
15SpringCloud - 断路器项目示例(Feign Hystrix)
19 0
|
6月前
|
监控 Java
14SpringCloud - 断路器项目示例(Ribbon Hystrix)
14SpringCloud - 断路器项目示例(Ribbon Hystrix)
22 0
|
5月前
|
缓存 运维 监控
微服务技术系列教程(22) - SpringCloud- 服务保护机制Hystrix
微服务技术系列教程(22) - SpringCloud- 服务保护机制Hystrix
60 0
|
6月前
|
缓存 监控 Java
12SpringCloud - 断路器(Hystrix)引入
12SpringCloud - 断路器(Hystrix)引入
28 0
|
6月前
|
Java 微服务 Spring
Spring Cloud Hystrix简单实用
Spring Cloud Hystrix简单实用
58 0