Hystrix提供了Hystrix Dashboard来实时监控HystrixCommand方法的执行情况。 Hystrix Dashboard可以有效地反映出每个Hystrix实例的运行情况,帮助我们快速发现系统中的问题,从而采取对应措施。
需要创建dashboard监控的服务消费者
添加pom jar依赖
<?xml version="1.0"?><projectxsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><modelVersion>4.0.0</modelVersion><parent><groupId>com.junjay</groupId><artifactId>SpringCloud</artifactId><version>0.0.1-SNAPSHOT</version></parent><groupId>com.junjay</groupId><artifactId>springcloud-consumer-hystrix-dashboard</artifactId><version>0.0.1-SNAPSHOT</version><name>springcloud-consumer-hystrix-dashboard</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency><!-- 消费者只需要实体类+web --><dependency><groupId>com.junjay</groupId><artifactId>springcloud-pai</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId></dependency><!-- 热部署工具 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId></dependency><!-- 添加负载均衡Ribbon依赖 --><!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-ribbon --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-ribbon</artifactId><version>1.4.6.RELEASE</version></dependency><!-- 加入eureka依赖进行服务注册 --><!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId><version>1.4.6.RELEASE</version></dependency><!-- 增加hystrix依赖 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId><version>1.4.6.RELEASE</version></dependency><!-- 增加dashboard依赖 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix-dashboard</artifactId><version>1.4.6.RELEASE</version></dependency></dependencies></project>
配置yml文件
#服务消费者只需要配置启动端口server:port: 9001
编辑主启动类
package org.springcloud;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;@SpringBootApplication@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })// 开启dashboard@EnableHystrixDashboardpublic class DeptConsumer_9001 {public static void main(String[] args) {SpringApplication.run(DeptConsumer_9001.class, args);}}
保证服务端都有监控actuator
<!-- actuator 完善监控信息 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>
启动服务9001
证明可以访问,启动成功,完整访问(豪猪)
豪猪(学名:Hystrix brachyura hodgsoni)
配置监控
在服务端启动类添加监控url
springcloud-provider-dept-8081服务添加
package org.springcloud;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.web.servlet.ServletRegistrationBean;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;import org.springframework.context.annotation.Bean;import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;// 启动类@SpringBootApplication// 开启eureka 在服务启动后自动将服务注册到eureka中@EnableEurekaClient// 服务发现及DeptController中的discovery方法@EnableDiscoveryClientpublic class DeptProvider_8081 {public static void main(String[] args) {SpringApplication.run(DeptProvider_8081.class, args);}// 增加一个servlet@Beanpublic ServletRegistrationBean hystrixMetricsStreamServlet() {ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());// Single Hystrix应用程序: http://hystrix-app:port/actuator/hystrix.streamregistrationBean.addUrlMappings("/actuator/hystrix.stream");return registrationBean;}}
访问localhost:8081/actuator/hystrix.stream
在dashboard中监控localhost:8081/actuator/hystrix.stream
Dashboard监控一直是Loading ping:一直都是空的
https://blog.csdn.net/qq_38788216/article/details/103929756
错误原因是一直链接不到eureka

需要加在有熔断机制服务中,
