失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 微服务学习之Hystrix图形化DashBoard监控【Hoxton.SR1版】

微服务学习之Hystrix图形化DashBoard监控【Hoxton.SR1版】

时间:2023-02-22 21:59:43

相关推荐

微服务学习之Hystrix图形化DashBoard监控【Hoxton.SR1版】

目录

1 前言

2 新建module

2.1 pom.xml

2.2 application.yml

2.3 启动类

2.4 启动项目

2.5 监控

1 前言

除了隔离依赖服务的调用以外,Hystrix还提供了准实时调用监控(Hystrix Dashboard),Hystrix会持续记录所有通过Hystrix发起请求的执行信息,并以统计报表和图形的形式展示给用户,包括每秒执行多少请求,有多少是成功的,有多少是失败的。

Netflix通过hystrix-metrics-event-stream项目实现了对以上项目的监控。SpringCloud提供了对Hystrix Dashboard的整合,将监控内容转换为可视化页面。

2 新建module

2.1 pom.xml

<?xml version="1.0" encoding="UTF-8"?><project xmlns="/POM/4.0.0"xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"><parent><artifactId>cloud</artifactId><groupId>com.bighuan.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>cloud-consumer-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><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><mainClass>com.bighuan.springcloud.HystrixDashboardMain9001</mainClass></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>

2.2 application.yml

只指定端口为9001,没有其他配置。

2.3 启动类

通过@EnableHystrixDashboard开启Hystrix Dashboard

@SpringBootApplication@EnableHystrixDashboard // 开启hystrix dashboardpublic class HystrixDashboardMain9001 {public static void main(String[] args) {SpringApplication.run(HystrixDashboardMain9001.class, args);}}

2.4 启动项目

访问hystrix:http://127.0.0.1:9001/hystrix

2.5 监控

1)在新版本Hystrix监控的项目主启动类中需要指定监控路径,否则会报错。如下被监控服务的主启动类:

@SpringBootApplication@EnableEurekaClient@EnableCircuitBreakerpublic class PaymentHystrixMain8001 {public static void main(String[] args) {SpringApplication.run(PaymentHystrixMain8001.class, args);}/*** 此配置是为了hystrix服务监控而配置,与服务容错本身无关,SpringCloud升级后的坑*ServletRegistrationBean因为SpringBoot的默认路径不是/hystrix.stream* 只要在自己的项目上配置好下面的servlet即可*/@Beanpublic ServletRegistrationBean getServlet(){HystrixMetricsStreamServlet streamServlet=new HystrixMetricsStreamServlet();ServletRegistrationBean registrationBean=new ServletRegistrationBean(streamServlet);registrationBean.setLoadOnStartup(1);registrationBean.addUrlMappings("/hystrix.stream");registrationBean.setName("HystrixMetricsStreamServlet");return registrationBean;}}

启动被监控的服务类,在Hystrix Dashboard页面进行监控:

点击Monitor Stream,进入信息监控页面(并访问被监控的8001项目):

说明:

如果觉得《微服务学习之Hystrix图形化DashBoard监控【Hoxton.SR1版】》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。