Dashboard可視化監控Hystrix數據

一、使用Hystrix Dashboard可視化監控數據

前文討論了Hystrix的監控,但都需要通過/hystrix.stream端點獲得數據再以文字形式展示的。辨識度很低。

接下來我們使用Hystrix Dashboard讓數據圖形化、可視化。

1、創建項目eureka-client-hystrix-dashboard

2、添加配置,pom.xml如下

<?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>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.6.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.springclouddemo</groupId>
	<artifactId>eureka-client-hystrix-dashboard</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>eureka-client-hystrix-dashboard</name>
	<description>可視化監控數據</description>

	<properties>
		<java.version>1.8</java.version>
		<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</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>

3、編寫application配置文件

spring.application.name=eureka-client-hystrix-dashboard
server.port=7210
eureka.client.service-url.defaultZone=http://localhost:7000/eureka/
eureka.instance.prefer-ip-address=true

4、爲main類添加@EnableHystrixDashboard註解

package com.springclouddemo.eurekaclienthystrixdashboard;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

/**
 * @author 何昌傑
 */
@SpringBootApplication
@EnableHystrixDashboard
@EnableEurekaClient
public class EurekaClientHystrixDashboardApplication {

	public static void main(String[] args) {
		SpringApplication.run(EurekaClientHystrixDashboardApplication.class, args);
	}

}

5、啓動main類

訪問http://localhost:7210/hystrix,可以看到Hystrix Dashboard的首頁

在URL欄輸入http://localhost:7209/hystrix.stream,隨意設置一個title點擊Monitor Stream添加一個監控。如下:

剛開始我們添加成功後只能看到Loading,沒有具體的數據,放我們調用一次http://localhost:7209/hello/hcj接口後可視化監控頁面將會有圖形數據產生。

附一張參數解釋圖:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章