目标:
创建一个Dashboard 服务模块,输入配置有Dashboard的模块控制地址,可以监控地址的健康状况。
步骤:
1. 创建一个Dashboard 模块项目 SpringbootHystrixDashboard ,加入dashboard 支持依赖。

<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>SpringbootHystrixDashboard</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
<version>1.4.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
<version>1.5.12</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2. 配置Application.peroperties 文件
server.port=9100
spring.application.name=Dashbaord
3.启动类上加入Dashboard的注解

@EnableHystrixDashboard
4. 启动danshboard 模块服务。在浏览器中访问dashboard 页面, 出现以下界面说明dashboard 服务配置成功。
URL : http://192.168.242.1:9100/hystrix

5. 在Consumer1 模块pom加入 dashboard 的支持依赖,用于dashboard 测试。

6. 在Consumer1 模块Application.properties 中开启短点控制权限

7.启动Consumer1
8. 在浏览器中打开dashboard 界面 http://192.168.242.1:9100/hystrix ,输入Consumer1 的测试地址。点击【Monitor Stream】按钮。
http://localhost:7001/actuator/hystrix.stream


调用测试接口并刷新dashboard detail页面 ,dashboard 页面监控数据有变化。数据含义请参照detail 页面右上方的颜色对应说明。
测试接口:http://localhost:7001/hystrixTest ,


9. 通过访问Consumer1 的/actuator/hystrix.stream 地址可以访问Dashboard 相关的数据。
URL:http://192.168.242.1:7001/actuator/hystrix.stream

如果界面出现ping ping ping .... , 请先访问一次测试接口地址即可出现dashboard 数据。
本文介绍如何创建一个Spring Boot Hystrix Dashboard模块来监控服务健康状态。具体步骤包括配置Maven依赖、设置启动类注解、启动Dashboard服务及验证监控功能等。

被折叠的 条评论
为什么被折叠?



