从springboot到springcloud第六篇----Hystrix dashboard

上一篇写了hystrix熔断器。

其实还不算完,因为还需要监控服务的运行情况,所以这一章写服务监控hystrix-dashboard

一、和ribbon配合使用

1.1 在ribbon-client项目的pom文件中添加依赖

        <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>

1.2 在启动类上添加注解@EnableHystrixDashboard

package com.example.ribbonclient;

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

@SpringBootApplication
@EnableEurekaClient
@EnableHystrix
@EnableHystrixDashboard
public class RibbonClientApplication {

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

}

1.3 运行测试

访问localhost:8700/hystrix,

依次在页面中输入localhost:8700/hystrix.stream、2000、index

然后点击Monitor Stream 按钮

如果是使用的spring2.0以上的版本,则会出现以下情况

因为acturtor默认只暴露了health和info端点,我们打开hystrix.stream端点即可

在pom文件中添加以下配置后重启ribbon-clientf服务并刷新页面

#打开hystix.stream端点(默认为打开,可以不写)
#management.endpoint.hystrix.stream.enabled=true
#对外暴露以下端点
management.endpoints.web.exposure.include=hystrix.stream,health,info

这时候页面处于Loading状态

这时候,另起一个标签页,访问http://localhost:8700/index 多次刷新后返回hystrix.stream标签页

这个时候服务信息已经出来了。

不知道什么意思?

打开浏览器的翻译功能(神器)

 

二、和feign配合使用

2.1 在pom文件中添加相同的配置,并同样添加配置文件

2.2 在启动类上添加注解@EnableCircuitBreaker

package com.example.feignclient;

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.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class FeignClientApplication {

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

}

2.3 启动测试

 

不过,这样也还不算完,因为一个微服务中不会仅仅只存在一个对多服务的负载均衡。我总不能挨个去配置吧,那样多麻烦,springcloud中也已经解决了(turbine组件)。

 

源码地址:https://github.com/houfanGitHub/springcloud.git

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值