新建项目hystrix-dashboard,添加Hystrix Dashboard依赖
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><groupId>com.example</groupId>
<artifactId>eureka-server-1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging><name>eureka-server-1</name>
<description>Demo project for Spring Boot</description><parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.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>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- 添加hystrix依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<!--添加hystrix-dashboard依赖 -->
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies><build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
启动类添加@EnableHystrixDashboard
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;@SpringBootApplication
//启动hystrix dashborad功能
@EnableHystrixDashboard
public class HystrixDashboardApplication {public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
启动项目,访问http://localhost:2001/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 开启,实现对具体某个服务室里的监控。
前面两个都是对集群的监控,需要整合Turbine才能实现。
下面是单个服务实例监控
输入框输入http://localhost:9000/hystrix.stream,点击Monitor Stream,如果没有请求会先显示Loading ...
启动eureka-server、eureka-server-1、eureka-ribbon-consumer和hystrix-dashboard这四个服务,调用http://localhost:9000/ribbon-consumer此时就会产生数据,完成后,再访问http://localhost:9000/hystrix.stream,可以看到生成的json文件
我们这时再看一下监控的页面
仪表图显示的数量指标如下图