前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringCloud详细教程 | 第十一篇:Hystrix Dashboard(断路器监控)(Greenwich版本)

SpringCloud详细教程 | 第十一篇:Hystrix Dashboard(断路器监控)(Greenwich版本)

作者头像
小东啊
发布2019-06-26 15:17:55
1.1K0
发布2019-06-26 15:17:55
举报
文章被收录于专栏:李浩东的博客李浩东的博客

一、Hystrix Dashboard简介

在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。

二. 环境搭建

我只想说一句 因为版本的原因真是各种坑 但是还是爱你的

在之前的feign-server服务基础上改造

1.引入依赖

由于是spring boot 2.1.X版本问题 所以

代码语言:javascript
复制
<!--监控检查依赖-->        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-actuator</artifactId>        </dependency>        <!--hystrix监控面板 相关依赖-->        <dependency>            <groupId>com.netflix.hystrix</groupId>            <artifactId>hystrix-javanica</artifactId>            <version>RELEASE</version>        </dependency>        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>        </dependency>

代替

代码语言:javascript
复制
<dependency>      <groupId>org.springframework.cloud</groupId>      <artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency>
2.启动类
代码语言:javascript
复制
package com.li.feignserver;
import com.li.feignserver.server.EurekaCclientService;import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.web.servlet.ServletRegistrationBean;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;import org.springframework.context.annotation.Bean;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@EnableHystrix // 开启Hystrix @EnableHystrixDashboard // 开启Hystrix面板@RestController@EnableFeignClients // 开启Feign功能@EnableEurekaClient@SpringBootApplicationpublic class FeignServerApplication {
    public static void main(String[] args) {        SpringApplication.run(FeignServerApplication.class, args);    }

    @Resource    private EurekaCclientService eurekaCclientService;
    @GetMapping("/hello")    public String hello(@RequestParam(value = "name") String name) {        return eurekaCclientService.hello(name);    }}
3.application.properties 配置文件 增加配置
代码语言:javascript
复制
# 端点放开management.endpoints.web.exposure.include=*

然后依次启动服务 eureka-server-> eureka-client -> feign-server

eureka-server : 8761端口

eureka-client: 8763端口

feign-server : 8766端口

打开浏览器输入 http://localhost:8761/

服务已经注册进来了

然后访问仪表盘服务地址:http://localhost:8766/hystrix

图中会有一些提示:

Cluster via Turbine (default cluster): http://turbine-hostname:port/turbine.stream Cluster via Turbine (custom cluster): http://turbine-hostname:port/turbine.stream?cluster=[clusterName] Single Hystrix App: http://hystrix-app:port/actuator/hystrix.stream 大概意思就是如果查看默认集群使用第一个url,查看指定集群使用第二个url,单个应用的监控使用最后一个,我们暂时只演示单个应用的所以在输入框中输入: http://localhost:8766/actuator/hystrix.stream ,输入之后点击 monitor,进入页面

然后使用feign调用服务 浏览器输入 http://localhost:8766/hello?name=lhd

指标有变化

(1)Deplay 该参数用来控制服务器上轮询监控信息的延迟时间,默认是2000毫秒,可以通过配置该属性来降低客户端的网络和cpu消耗。 (2)Title该参数对应了头部标题Hystrix Stream之后的内容,默认会使用哦具体监控实例的URL,可疑通过配置该信息来展示更合适的标题。

源码下载: https://github.com/LiHaodong888/SpringCloudLearn

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-04-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 李浩东的博客 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、Hystrix Dashboard简介
  • 二. 环境搭建
    • 1.引入依赖
      • 2.启动类
        • 3.application.properties 配置文件 增加配置
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档