SpringCloud(七)hystrix Dashboard

前言:

    官网解释如下:

One of the main benefits of Hystrix is the set of metrics it gathers about each HystrixCommand. 
The Hystrix Dashboard displays the health of each circuit breaker in an efficient manner.

Hystrix的主要优点之一是它收集的每个HystrixCommand的指标集。Hystrix指示板以一种有效的方式显示每个断路器的健康状况。

代码:
修改上一篇博客代码eureka client的代码

加入下面maven依赖:

        
            org.springframework.boot
            spring-boot-starter-actuator
        

        
            org.springframework.cloud
            spring-cloud-starter-hystrix-dashboard
        

actuator提供对服务的监控,dashboard为ui


要使用Dashboard必须加两个注解:

@EnableHystrix
//@EnableCircuitBreaker  //与@EnableHystrix 一样
@EnableHystrixDashboard
package com.xhx.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableHystrix
//@EnableCircuitBreaker  //与@EnableHystrix 一样
@EnableHystrixDashboard
public class EurekaFeignApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaFeignApplication.class, args);
    }
}
之前的Feign服务由于内置断路器支持, 所以没有 @EnableCircuitBreaker注解,但要使用Dashboard则必须加 ,如果不加,Dashboard无法接收到来自Feign内部断路器的监控数据,会报“Unable to connect to Command Metric Stream”错误

启动各个微服务:

打开http://127.0.0.1:8085/hystrix这个网址:

SpringCloud(七)hystrix Dashboard_第1张图片

按照上图输入,改成自己的ip和端口,点击monitor stream

发送几次请求

SpringCloud(七)hystrix Dashboard_第2张图片


SpringCloud(七)hystrix Dashboard_第3张图片

出现上图所示,证明监控成功了


我的github地址


参考:

Spring Cloud 入门教程(八): 断路器指标数据监控Hystrix Dashboard

你可能感兴趣的:(SpringCloud,SpringCloud)