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

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


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

    
    <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>demo2020artifactId>
            <groupId>cn.chen.demogroupId>
            <version>1.0-SNAPSHOTversion>
        parent>
        <modelVersion>4.0.0modelVersion>

        <artifactId>hystrix-dashboard-consumer9001artifactId>

        <dependencies>
            
            <dependency>
                <groupId>org.springframework.cloudgroupId>
                <artifactId>spring-cloud-starter-netflix-hystrix-dashboardartifactId>
            dependency>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-actuatorartifactId>
            dependency>

            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-devtoolsartifactId>
                <scope>runtimescope>
                <optional>trueoptional>
            dependency>

            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
                <optional>trueoptional>
            dependency>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-testartifactId>
                <scope>testscope>
            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.bootgroupId>
        <artifactId>spring-boot-starter-actuatorartifactId>
    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学习系列目录

你可能感兴趣的:(springcloud学习笔记)