一、Hystrix Dashboard简介
在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。
二、创建Module->microservicecloud-consumer-hystrix-dashboard
创建前请先创建 microservicecloud-provider-dept-hystrix 参考(SpringCloud教程 | 第N篇:断路器(Hystrix))
2.1 豪猪 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"> <parent> <artifactId>mall</artifactId> <groupId>com.linjia</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>microservicecloud-consumer-hystrix-dashboard</artifactId> <name>microservicecloud-consumer-hystrix-dashboard</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>com.linjia</groupId> <artifactId>microservicecloud-api</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- hystrix和 hystrix-dashboard相关 --> <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> <!-- Ribbon相关 Ribbon与zookeeper区别,zookeeper 高一致性,ribbon 高可用--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-ribbon</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <!-- 修改后立即生效,热部署 --> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> <!-- web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <finalName>${name}</finalName> </build> </project>
2.2 豪猪 yml配置
server: port: 9001 # provider 中pom 中添加 # <!-- actuator监控信息完善 --> # <dependency> # <groupId>org.springframework.boot</groupId> # <artifactId>spring-boot-starter-actuator</artifactId> # </dependency> #http://localhost:9001/hystrix 访问
2.3 豪猪 启动类
package com.linjia.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @SpringBootApplication @EnableHystrixDashboard //启动豪猪 public class DashBoard_Application { public static void main(String[] args) { SpringApplication.run(DashBoard_Application.class, args); } }
启动项目:启动注册中心eureka,
启动 microservicecloud-provider-dept-hystrix(注意修改POM监控配置)
启动
microservicecloud-consumer-hystrix-dashboard
# 启动项目后访问 # 第一步:http://localhost:8002/dept/get/1 # 第二步:http://localhost:8002/hystrix.stream # 第三步: 启动microservicecloud-consumer-hystrix-dashboard # 第四步:http://localhost:9001/hystrix
配置 :http://localhost:9001/hystrix 内容
查看结果:
实心圆:共有两种含义,它通过颜色的变化代表了实例的健康程度,他的健康度从 绿色<黄色<橙色<红色 递减;
圆的大小变化:流量越大改实心圆就越大;