Hystrix搭建Dashboard发生Unable to connect to Command Metric Stream.

Spring Cloud Netfilx出现Unable to connect to Command Metric Stream.问题。
监控不到可能出现的原因:
1.监控服务确保都加入监控引入actuator依赖
2.服务端启动类需要加入ServletRegistrationBean处理
3.请求方法需要加入熔断器hystrix
4.注意版本差异
在这里插入图片描述

  1. 服务端加入监控依赖
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
  1. 服务端启动类代码
package com;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.mybatis.spring.annotation.MapperScan;
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
@MapperScan("com.mapper")
@EnableCircuitBreaker
public class AppMysqlDB1Run {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(AppMysqlDB1Run.class);
    }

	//需加入该关键代码
    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet(){
    
    
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        registrationBean.addUrlMappings("/actuator/hystrix.stream");
        return registrationBean;
    }
}

  1. 创建Dashboard项目
    <dependencies>

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

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>

    </dependencies>
  1. 启动类代码
package com;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableHystrixDashboard
public class AppActuatorRun {
    
    

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

}

  1. 启动Dashboard,进入http://localhost:8085/hystrix/
    在这里插入图片描述
  2. 填入服务端链接如:http://localhost:8081/actuator/hystrix.stream,Delay默认2000就行,title随意
    在这里插入图片描述
  3. 进入后有请求会看到该页面,没请求就一直出现loding长时间后就会Unable to connect to Command Metric Stream.
    在这里插入图片描述
  4. 请求一定要是hystrix配置熔断的方法才有效,不然监控不到
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Lilayzzz/article/details/108314027
今日推荐