SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据

摘要:
本文描述了如何监视服务以及如何使用HystrixDashboard可视化监视数据。使用HystrixDashboard可视化监控数据1.创建子模块项目sc Hystrix dashboard,pom。xml:4.0.0com.cfsc part0.0.1-SNAPSHOTsc crystal dashboard˂groupId=org.springframework.cloud春季云启动netflix x-hyphen-dashboard2。创建启动类仪表板。Das-hBoardApplication:packagedashboard;importorg.springframework.boot。SpringApplication;importorg.springframework.boot.au配置。SpringBootApplication;importorg.springframework.cloud.netflix.hystrix.dashboard。EnableHystrixDashboard;@SpringBootApplication@EnableHystrixDashboardpublicclassDashBoardApplication{publicstaticvoidmain{SpringApplication.run;}}3.创建应用程序。yml:server:port:8086spring:application:name:sc histrix dashboard 4.启动sc histrix仪表板后,访问http://localhost:8086/hystrix将显示HystrixDashboard的主界面:然后,需要将消费者sc消费者Hystrix foreign的监控数据添加到Hystrix Dashboard。通过Turbine,您可以聚合所有/htrix的数据。将端点流到组合/涡轮机中。流,然后在HystrixDashboard中查看所有服务的监控信息。

简介

上篇文章中讲了使用Hystrix实现容错,除此之外,Hystrix还提供了近乎实时的监控。本文将介绍如何进行服务监控以及使用Hystrix Dashboard来让监控数据图形化。

项目介绍

  1. sc-parent,父模块(请参照SpringCloud学习笔记(1):Eureka注册中心)
  2. sc-eureka,注册中心(请参照SpringCloud学习笔记(1):Eureka注册中心)
  3. sc-consumer-hystrix-ribbon,使用Hystrix+Ribbon的消费者(请参照SpringCloud学习笔记(4):Hystrix容错机制)
  4. sc-consumer-hystrix-feign,使用Hystrix+Feign的消费者(请参照SpringCloud学习笔记(4):Hystrix容错机制)
  5. sc-hystrix-dashboard,用于可视化监控数据
  6. sc-turbine,用于聚合监控数据

开启消费者服务监控

1.修改消费者sc-consumer-hystrix-ribbon和sc-consumer-hystrix-feign的pom.xml,新增如下依赖:

	<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

2.修改消费者sc-consumer-hystrix-ribbon和sc-consumer-hystrix-feign的application.yml,新增如下配置:

management:
  endpoints:
    web:
      exposure:
        include: 'hystrix.stream'  #暴露hystrix.stream端点

3.测试访问消费者sc-consumer-hystrix-feign的监控数据

依次启动注册中心sc-eureka和消费者sc-consumer-hystrix-feign,并访问http://localhost:8084/actuator/hystrix.stream,结果显示如下:
SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据第1张

出现上图是因为消费者服务没有被访问,所以这里先调用下消费者服务:http://localhost:8084/feign/getBookList,然后再访问http://localhost:8084/actuator/hystrix.stream:

SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据第2张

可以看到监控数据是以文字的形式展示的,并不直观,下面将介绍使用Hystrix Dashboard可视化监控数据。

使用Hystrix Dashboard可视化监控数据

1.在父模块下创建子模块项目sc-hystrix-dashboard,pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.cf</groupId>
    <artifactId>sc-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>sc-hystrix-dashboard</artifactId>
  
  <dependencies>
  	<dependency>
	    <groupId>org.springframework.cloud</groupId>
	    <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
	</dependency>
  </dependencies>
</project>

2.创建启动类dashboard.DashBoardApplication:

package dashboard;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

@SpringBootApplication
@EnableHystrixDashboard
public class DashBoardApplication {
	public static void main(String[] args) {
		SpringApplication.run(DashBoardApplication.class, args);
	}
}

3.创建application.yml:

server:
  port: 8086

spring:
  application:
    name: sc-hystrix-dashboard

4.测试

启动sc-hystrix-dashboard后,访问http://localhost:8086/hystrix将会显示Hystrix Dashboard的主界面:

SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据第3张

然后需要将消费者sc-consumer-hystrix-feign的监控数据添加到Hystrix Dashboard中。依次启动注册中心sc-eureka和消费者sc-consumer-hystrix-feign,将监控数据的地址输入到Hystrix Dashboard主界面的文本框中,点击Monitor Stream,然后重复访问消费者服务http://localhost:8084/feign/getBookList,Hystrix Dashboard显示如下:

SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据第4张

关于界面上指标表示的内容可以参考下图:
SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据第5张

使用Turbine聚合监控数据

/hystrix.stream端点只能监控到单个服务实例,如果需要查看其他服务实例监控信息则需要在Hystrix Dashboard切换想要监控的地址。通过Turbine可以将所有/hystrix.stream端点的数据聚合到一个组合的/turbine.stream中,然后在Hystrix Dashboard中就可以查看所有服务的监控信息。

1.修改消费者sc-consumer-hystrix-ribbon和sc-consumer-hystrix-feign的application.yml,将registerWithEureka设为true或者直接去掉该配置(默认为true)。因为Turbine需要从Eureka上获取服务的地址信息,然后才能获取到服务的监控数据,所以消费者服务需要到Eureka注册中心注册。

eureka:
  client:
    #registerWithEureka: false 
    serviceUrl:
      defaultZone: http://localhost:8080/eureka/  

2.在父模块下创建子模块项目sc-turbine,pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.cf</groupId>
    <artifactId>sc-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>sc-turbine</artifactId>
  
  <dependencies>
  	<dependency>
	    <groupId>org.springframework.cloud</groupId>
	    <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
	</dependency>
  </dependencies>
</project>

3.创建启动类turbine.TurbineApplication:

package turbine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@SpringBootApplication
@EnableTurbine
public class TurbineApplication {
	public static void main(String[] args) {
		SpringApplication.run(TurbineApplication.class, args);
	}
}

4.创建application.yml:

server:
  port: 8087

spring:
  application:
    name: sc-turbine
    
eureka:
  client:
    registerWithEureka: false
    serviceUrl:
      defaultZone: http://localhost:8080/eureka/    

turbine:
  appConfig: sc-consumer-hystrix-ribbon,sc-consumer-hystrix-feign #指定要监控的服务名
  clusterNameExpression: "'default'"

5.测试

依次启动注册中心sc-eureka、消费者sc-consumer-hystrix-feign、消费者sc-consumer-hystrix-ribbon、sc-turbine、sc-hystrix-dashboard,访问http://localhost:8086/hystrix进入到Hystrix Dashboard主界面中,然后在Hystrix Dashboard主界面的文本框中输入http://localhost:8087/turbine.stream,点击Monitor Stream进入监控界面,重复访问两个消费者服务,监控界面上将显示两个消费者的监控信息:

SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据第6张

免责声明:文章转载自《SpringCloud学习笔记(5):Hystrix Dashboard可视化监控数据》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇sql注入100种姿势过waf(一):waf 了解ubuntu16.04上安装深度学习环境下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

数据可视化:python matplotlib小试牛刀

Matplotlib有两个模块: 1) 绘图API:pyplot, 可这样导入import matplotlib.pyplot as plt    2)集成库:pylab, 是matplotlib Scipy Numpy的集成库 import pandas as pd import matplotlib.pyplot as plt from pylab i...

Bootstrap部分---环境安装及一个可视化的布局;

一:环境安装*****顺序不可变***** <head> 如果需要可以设定,移动设备优先 <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!--1.引入 Bootstrap---> <link href="../../....

8-25 Hystrix两种应用场景介绍

Hytrix在我们的表现层之外,再包装一层Command,也就是表现层在调其它层业务逻辑的时候,他就会把HystrixCommand再封装一层,根据你的隔离级别,再访问其他的业务情况,然后紧接着处理,处理后再返回,这是我们第一种场景。也就是HystrixCommand是写在表现层中的另外一种场景,区别在于,下面的红框把整个表现层都包起来了。也就是当我们的请...

一文带你了解微服务架构和设计(多图)

最近几年微服务很火,大家都在建设微服务,如果不懂点微服务相关的技术,都不好意思跟同行打招呼了,也见过身边很多人在微服务踩过很多坑,我从 16 年开始接触微服务,有多家大型企业的微服务分布式系统的架构经验,所以就打算跟大家做一期关于微服务的分享,不过微服务和涉及的分布式计算非常的复杂,绝非是一篇文章就可以讲清楚的,本文只是从最简单的概念的基本使用带你入门,...

基于WebGL的三维交通监控可视化技术应用(实践版) ThingJS

三维可视化##3D开发# WebGL, SVG,BIM技术对比 ThingJS整合Echarts数据分析 隧道监控三维可视化5大场景 互联网技术为交通行业的可视化带来了多样性的发展。从传统的二维平面变形图、二维SVG矢量图到如今的SVG三维矢量技术、BIM技术、GIS+BIM技术、 WebGL技术,甚至连AR、VR、MR等虚拟现实技术,也开始应用于交通领域...

k8s部署使用Dashboard(十)

安装Dashboard 前面博客Kubernetes 所有的操作我们都是通过命令行工具 kubectl 完成的。为了提供更丰富的用户体验,Kubernetes 还开发了一个基于 Web 的 Dashboard,用户可以用 Kubernetes Dashboard 部署容器化的应用、监控应用的状态、执行故障排查任务以及管理 Kubernetes 各种资源。...