SpringCloud HystrixDashboard服务监控详解

Hystrix Dashboard 是Spring Cloud中查看Hystrix实例执行情况的一种仪表盘组件,支持查看单个实例和查看集群实例,本文将对其服务监控学习

hystrixDashboard服务监控

除了隔离依赖服务的调用以外,Hystrix还提供了准实时的调用监控(Hystrix Dashboard),Hystrix会持续地记录所有通过Hystrix发起的请求的执行信息,并以统计报表和图形的形式展示给用户,包括每秒执行多少请求多少成功,多少失败等。Netflix通过hystrix-metrics-event-stream项目实现了对以上指标的监控。Spring Cloud也提供了Hystrix Dashboard的整合,对监控内容转化成可视化界面。

1、新建cloud-consumer-hystrix-dashboard9001仪表盘监控模块

2、修改pom.xml文件引入仪表盘依赖

核心依赖:spring-cloud-starter-netflix-hystrix-dashboard

注意:所有的图形化展示,都需要引入spring-boot-starter-actuator依赖,在8001、8002上都需要引入

   springcloud2022com.zcl.springcloud1.0-SNAPSHOT4.0.0cloud-consumer-hystrix-dashboard9001 88  org.springframework.cloudspring-cloud-starter-netflix-hystrix-dashboard org.springframework.bootspring-boot-starter-actuator org.springframework.bootspring-boot-devtoolsruntimetrue org.projectlomboklomboktrue org.springframework.bootspring-boot-starter-testtest

3、添加YAML配置文件

server:
  port: 9001

4、建立启动类

必须要加上@EnableHystrixDashboard注解激活

package com.zcl.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; /** * 描述:仪表盘启动类 */ @SpringBootApplication @EnableHystrixDashboard public class HystrixDashboardMain9001 { public static void main(String[] args) { SpringApplication.run(HystrixDashboardMain9001.class, args); } }

5、启动项目

启动项目测试:http://localhost:901/hystrix

使用方法:在下面页面中输入需要进行监控的地址即可

断路器演示监控

监控8001注意事项

1、必须要有如下的两个依赖

 org.springframework.bootspring-boot-starter-web org.springframework.bootspring-boot-starter-actuator

2、对启动类的修改

注意:新版本Hystrix需要在主启动类MainAppHystrix8001中指定监控路径,否则会出现报错

package com.zcl.springcloud; 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.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.annotation.Bean; /** * 描述:熔断限流启动类 */ @SpringBootApplication @EnableEurekaClient @EnableCircuitBreaker public class PaymentHystrixMain8001 { public static void main(String[] args) { SpringApplication.run(PaymentHystrixMain8001.class, args); } /** *此配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑 *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; } }

监控测试

启动7001Eureka服务中心

观察监控窗口

9001监控8001

8001地址测试

先访问正确地址,再访问错误地址,再正确地址,会发现图示断路器都是慢慢放开的。

http://localhost:8001/payment/circuit/31:正常的访问

http://localhost:8001/payment/circuit/-31:异常访问

监控状态

到此这篇关于SpringCloud HystrixDashboard服务监控详解的文章就介绍到这了,更多相关SpringCloud HystrixDashboard内容请搜索0133技术站以前的文章或继续浏览下面的相关文章希望大家以后多多支持0133技术站!

以上就是SpringCloud HystrixDashboard服务监控详解的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Java