1.概述

《SpringCloud专题19》-服务监控hystrixDashboard_maven

2.仪表盘9001

新建cloud-consumer-hystrix-dashboard9001
《SpringCloud专题19》-服务监控hystrixDashboard_spring_02
POM

<?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>springcloud2020</artifactId>
<groupId>com.itxiongmao.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>cloud-comsumer-hystrix-dashboard9001</artifactId>

<dependencies>

<!--hystrix dashboard-->
<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-actuator</artifactId>
</dependency>

<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>

YML

server:
port: 9001

HystrixDashboardMain9001+新注解@EnableHystrixDashboard

package com.itxiongmao;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableHystrixDashboard
public class DashboardMain9001 {
public static void main(String[] args) {
SpringApplication.run(DashboardMain9001.class,args);
}
}

所有Provider微服务提供类(8001/8002/8003)都需要监控依赖部署
《SpringCloud专题19》-服务监控hystrixDashboard_spring_03
启动cloud-consumer-hystrix-dashboard9001该微服务后续将监控微服务8001
​​​ http://localhost:9001/hystrix​《SpringCloud专题19》-服务监控hystrixDashboard_spring_04

3.断路器演示(服务监控hystrixDashboard)

修改cloud-provider-hystrix-payment8001
注意:新版本Hystrix需要在主启动MainAppHystrix8001中指定监控路径

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;

/**
* @author zzyy
* @create 2020/3/7 17:27
**/
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardMain9001 {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardMain9001.class);
}

/**
* 此配置是为了服务监控而配置,与服务容错本身无观,springCloud 升级之后的坑
* ServletRegistrationBean因为springboot的默认路径不是/hystrix.stream
* 只要在自己的项目中配置上下面的servlet即可
* @return
*/
@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}

Unable to connect to Command Metric Stream. 404

监控测试:
启动一个eureka或者3个eureka集群均可
观察监控窗口
9001监控8001
《SpringCloud专题19》-服务监控hystrixDashboard_maven_05
填写监控地址

http://localhost:8001/hystrix.stream

测试地址

http://localhost:8001/payment/circuit/31
http://localhost:8001/payment/circuit/-31

上述测试通过
先访问正确地址,再访问错误地址,再正确地址,会发现图标断路器都是慢慢放开的.
监控结果,成功
《SpringCloud专题19》-服务监控hystrixDashboard_spring_06
监控结果,失败
《SpringCloud专题19》-服务监控hystrixDashboard_spring_07

4.如何看?

7色
《SpringCloud专题19》-服务监控hystrixDashboard_spring_08
1圈
《SpringCloud专题19》-服务监控hystrixDashboard_maven_09
1线
《SpringCloud专题19》-服务监控hystrixDashboard_maven_10
整图说明
《SpringCloud专题19》-服务监控hystrixDashboard_maven_11
《SpringCloud专题19》-服务监控hystrixDashboard_spring_12

整图说明2
《SpringCloud专题19》-服务监控hystrixDashboard_css_13
搞懂一个才能看懂复杂的
《SpringCloud专题19》-服务监控hystrixDashboard_css_14