第一步:引用依赖,将下面代码加入pom.xml中

<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.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>

第二步:给启动类加注解

@EnableHystrixDashboard

@EnableHystrix

@EnableCircuitBreaker

第三步:编写一个类

 @Bean
    public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    } 

操作结果如图:

第四步:重启服务;需确定好服务启动端口。因为底层是tomcat,所以服务端口,其实就是tomcat端口号:

第五步:访问hystrix监控(9097就是tomcat端口)

     如:http://111.230.199.202:9097/hystrix.stream 。就会获得返回的数据。

 

到此时你的配置就完全正确了。

第六步:图形化hystrix监控

先进入:http://111.211.111.211:9097/hystrix
进去后在文本框中输入:http://111.211.11.211:9097/hystrix.stream

即可获得监控页面了。

注意:

也许此时会报错;一定要先F12一下,查查是什么错误信息。

如果是下面这种情况,说明是返回的报文格式不正确,导致前端不能解析成功,这个目前还未找到解决之道。

 

posted on 2019-06-13 16:54  进_进  阅读(195)  评论(0)    收藏  举报