当前位置: 首页 > news >正文

Spring Cloud 入门教程5、服务容错监控:Hystrix Dashboard

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

一、前言

1、Hystrix Dashboard的作用?

上一篇我们介绍了Hystrix的基础使用,我们可以通过Hystrix做到依赖隔离和熔断等操作。但是只有工具的使用而没有监控,我们就无法在第一时间发现出现问题的依赖,也不能判断服务整体的健康状态/运行状态。所以我们还要做好相关的监控工作。

Hystrix提供了监控页面,本篇主要介绍如何使用Hystrix Dashboard对服务的容错情况进行监控。

2、本篇环境信息

框架版本
Spring Boot2.0.0.RELEASE
Spring CloudFinchley.BUILD-SNAPSHOT
JDK1.8.x

3、准备工作

  • 准备Eureka Server、服务提供者

参考:https://ken.io/note/spring-cloud-feign-quickstart
源码:https://github.com/ken-io/springcloud-course/tree/master/chapter-03/

启动Eureka Server: http://localhost:8800
启动Test Service:http://localhost:8602

  • 服务消费者准备

基于上一篇Feign+Hystrix:https://ken.io/note/spring-cloud-hystrix-quickstart
源码(feignclient):https://github.com/ken-io/springcloud-course/tree/master/chapter-04/feignclient

二、Hystrix Dashboard

基于feignclient项目使用Hystrix Dashboard

1、项目中引入Hystrix Dashboard

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

2、配置Hystrix Dashboard启动

修改App.java,增加 @EnableHystrixDashboard 注解

package io.ken.springcloud.feignclient;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;

@EnableHystrixDashboard
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class App {

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

}

3、配置HystrixMetricsStream访问入口

新建package:configuration,然后在此package下创建HystrixConfiguration.java并添加hystrixRegistrationBean

package io.ken.springcloud.feignclient.configuration;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class HystrixConfiguration {

    @Bean(name = "hystrixRegistrationBean")
    public ServletRegistrationBean servletRegistrationBean() {
        ServletRegistrationBean registration = new ServletRegistrationBean(
                new HystrixMetricsStreamServlet(), "/hystrix.stream");
        registration.setName("hystrixServlet");
        registration.setLoadOnStartup(1);
        return registration;
    }
}

4、Hystrix Dashboard测试

feignclient项目启动后,访问 http://localhost:8605/hystrix

将会看到Hystrix Dashboard导航页

image

Hystrix Dashboard导航页不会展示具体监控信息,而是提供三种选择:

  1. 默认的集群监控,通过URL:http://turbine-hostname:port/turbine.stream,查看默认集群的监控信息。

  2. 指定的集群监控,通过URL:http://turbine-hostname:port/turbine.stream?cluster=[clusterName],查看指定集群(clusterName)的监控信息。

  3. 单个实例的监控,通过URL:http://hystrix-app:port/hystrix.stream,查看具体某个服务实例的监控信息。

我们先通过Hystrix Dashboard看一下单个实例的监控信息
image

输入指定连接:http://localhost:8605/hystrix.stream
Delay(查询监控信息的延迟时间),Tile可以自定义,也可以默认。填写完毕点击 Monitor Stream 即可

image

此时Hystrix监控面板会显示Loanding…,这是因为我们还没通过feignclient访问外部接口,也就还没生成stream信息。
我们通过feignclient访问几个外部接口,stream信息生成后,监控面板会自动刷新。

image

在访问了 http://localhost:8605/ti ,http://localhost:8605/plus?numa=1&numb=2
这两个接口后,监控信息就自然刷新了。不同的接口默认会分开来记录。

监控图中用圆点来表示服务的健康状态,健康度从100%-0%分别会用绿色、黄色、橙色、红色来表示。
另外,这个圆点也会随着流量的增多而变大。
监控图中会用曲线(圆点旁边)来表示服务的流量情况,通过这个曲线可以观察单个接口的流量变化/趋势

上个图中是个非常小的绿色圆心,流量曲线也是个折现,是因为 ken.io 这里访问两个接口次数很少。
如果分别狂按F5快速访问这两个接口。这个圆心和曲线就会发生变化。

image

这时候这个圆点比着上一张图已经变大了,服务依旧是健康状态,所以圆点还是绿色。
另外流量曲线随着刚才的快速刷新访问也升了上去。

为了更好的展示服务不同健康状态下面板的变化,我们快速访问 http://localhost:8605/ti , http://localhost:8605/plus?numa=1&numb=2,然后关闭testservice,快速的访问 http://localhost:8605/plus?numa=1&numb=2 ,这首的面板会更丰富。

image

这时候TestService#plusService的圆点就变成了红色。由于停用testservice后我们没有访问 http://localhost:8605/ti ,所以这个时间点TestService#plusService的圆点还是绿色,尺寸也更小。两个Service的流量曲线变化也跟我们的操作相吻合。

image

上图是Hystrix Dashboard监控图表中各项指标的说明

转载于:https://my.oschina.net/wuweixiang/blog/3011414

相关文章:

  • rabbitmq单机多实例集群搭建
  • j2EE监听器-listener
  • jQuery EasyUI使用教程之使用虚拟滚动视图显示海量数据
  • DevOps团队结构类型汇总:总有一款适合你
  • CSS学习笔记(五)背景
  • 独家!支付宝小程序技术架构全解析
  • linux关闭ssh连接
  • [ JavaScript ] 数据结构与算法 —— 链表
  • [Redis]Redis的数据类型
  • Leetcode题目:Balanced Binary Tree
  • 我是如何设计 Upload 上传组件的
  • 团队项目第一阶段冲刺站立会议6(4月23日)
  • You must use the Role Management Tool to install or configure Microsoft .NET Framework 3.5 SP1
  • 云HBase Spark分析引擎对接云数据库POLARDB
  • Hive基本操作
  • [LeetCode] Wiggle Sort
  • Android交互
  • Angular 响应式表单之下拉框
  • canvas 绘制双线技巧
  • docker python 配置
  • FineReport中如何实现自动滚屏效果
  • Joomla 2.x, 3.x useful code cheatsheet
  • node学习系列之简单文件上传
  • Odoo domain写法及运用
  • React-redux的原理以及使用
  • scrapy学习之路4(itemloder的使用)
  • Sublime Text 2/3 绑定Eclipse快捷键
  • Vue.js 移动端适配之 vw 解决方案
  • Vue--数据传输
  • WePY 在小程序性能调优上做出的探究
  • 闭包,sync使用细节
  • 关于 Linux 进程的 UID、EUID、GID 和 EGID
  • 关于for循环的简单归纳
  • 两列自适应布局方案整理
  • 责任链模式的两种实现
  • 看到一个关于网页设计的文章分享过来!大家看看!
  • 白色的风信子
  • ​一帧图像的Android之旅 :应用的首个绘制请求
  • #传输# #传输数据判断#
  • $refs 、$nextTic、动态组件、name的使用
  • (10)Linux冯诺依曼结构操作系统的再次理解
  • (delphi11最新学习资料) Object Pascal 学习笔记---第7章第3节(封装和窗体)
  • (done) NLP “bag-of-words“ 方法 (带有二元分类和多元分类两个例子)词袋模型、BoW
  • (done) 两个矩阵 “相似” 是什么意思?
  • (Repost) Getting Genode with TrustZone on the i.MX
  • (八)Spring源码解析:Spring MVC
  • (附源码)springboot优课在线教学系统 毕业设计 081251
  • (附源码)ssm码农论坛 毕业设计 231126
  • (一)C语言之入门:使用Visual Studio Community 2022运行hello world
  • (转)memcache、redis缓存
  • (转)ObjectiveC 深浅拷贝学习
  • (转载)PyTorch代码规范最佳实践和样式指南
  • .NET Core WebAPI中使用Log4net 日志级别分类并记录到数据库
  • .net 按比例显示图片的缩略图
  • .NET 中使用 TaskCompletionSource 作为线程同步互斥或异步操作的事件