springcloud学习-13 服务监控hystrixDashboard【周阳springcloud2020学习笔记】

    技术2022-07-11  109

    Hystrix-dashboard是一款针对Hystrix进行实时监控的可视化图形工具。 通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。


    1.新建 hystrix-dashboard-consumer9001 2.pom.xml

    <?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>demo2020</artifactId> <groupId>cn.chen.demo</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>hystrix-dashboard-consumer9001</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>

    3.yml

    server: port: 9001

    4.主启动类:添加注解 @EnableHystrixDashboard 开启熔断监控支持

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

    所有Provider微服务提供类(8001/8002/8003)都需要监控依赖配置

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>

    启动cloud-consumer-hystrix-dashboard9001该微服务后续将监控微服务8001 http://localhost:9001/hystrix


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

    @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; }

    没添加会出现 Unable to connect to Command Metric Stream 404


    监控测试 1.启动eureka 2.观察监控窗口 9001监控8001:填写监控地址,http://localhost:8001/hystrix.stream 测试:http://localhost:8001/payment/circuit/31 http://localhost:8001/payment/circuit/-31

    springcloud学习系列目录

    Processed: 0.010, SQL: 9