Spring Cloud hystrix-dashboard监控服务搭建

一、我的版本

spring boot:2.2.2.RELEASE

spring cloud:Hoxton.SR1

二、已搭建服务

spring-cloud-eureka

spring-cloud-server

spring-cloud-consumer

1、以上服务需要有这两个依赖


    org.springframework.boot
    spring-boot-starter-actuator



    org.springframework.boot
    spring-boot-starter-web

2、 我的spring-cloud-consumer服务是用openfeign组件实现服务熔断

三、搭建监控服务

spring-cloud-monitor

pom依赖:


    org.springframework.boot
    spring-boot-starter-actuator



    org.springframework.boot
    spring-boot-starter-web



    org.springframework.cloud
    spring-cloud-starter-netflix-eureka-client



    org.springframework.cloud
    spring-cloud-starter-netflix-hystrix-dashboard

主启动类:

加上@EnableHystrixDashboard注解

四、修改consumer服务

pom依赖:

添加hystrix依赖


    org.springframework.cloud
    spring-cloud-starter-netflix-hystrix

主启动类:

@SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
public class SpringCloudConsumer1Application {

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

//	 此配置是为了服务监控而配置,与服务容错本身无关,
//	 ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",
//	 只要在自己的项目里配置上下面的servlet就可以了
	@Bean
	public ServletRegistrationBean getServlet() {
		HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
		registrationBean.setLoadOnStartup(1);
		registrationBean.addUrlMappings("/hystrix.stream");
		registrationBean.setName("HystrixMetricsStreamServlet");
		return registrationBean;
	}

}

五、测试查看

输入地址查看http://localhost:6001/hystrix

Spring Cloud hystrix-dashboard监控服务搭建_第1张图片

监控的信息 

 Spring Cloud hystrix-dashboard监控服务搭建_第2张图片

六、参考文章

https://www.cnblogs.com/jinjiyese153/p/9172885.html

 

你可能感兴趣的:(Spring,Cloud)