服务容错保护断路器Hystrix之三:断路器监控(Hystrix Dashboard)
2017-09-15 11:22
896 查看
一、Hystrix Dashboard简介
在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。二、准备工作
本文涉及2个工程:一个有熔断功能的示例,前面文章《服务容错保护断路器Hystrix之一:入门介绍》中的ribbon-consumer
一个是新建的断路器监控(Hystrix Dashboard)工程
三、开始创建断路器监控(Hystrix Dashboard)
创建一个hystrix-dashboard的springboot工程,pom的工程文件引入相应的依赖:<?xml version="1.0" encoding="UTF-8"?> <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> <groupId>com.dxz.dashboard</groupId> <artifactId>dashboard</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>hystrix-dashboard</name> <description>dashboard project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.5.RELEASE</version> <!--配合spring cloud版本 --> <relativePath /> <!-- lookup parent from repository --> </parent> <properties> <!--设置字符编码及java版本 --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <!--增加hystrix的依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> <!--增加dashboard的依赖 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> </dependency> <!--用于测试的,本例可省略 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <!--依赖管理,用于管理spring-cloud的依赖 --> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-parent</artifactId> <version>Brixton.SR3</version> <!--官网为Angel.SR4版本,但是我使用的时候总是报错 --> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <!--使用该插件打包 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
在程序的入口HystrixDashboardApplication类,加上@EnableHystrixDashboard注解开启断路器,开启HystrixDashboard
package com.dxz.dashboard; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @EnableHystrixDashboard @SpringBootApplication public class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); } }
配置端口信息application.properties
spring.application.name=hystrix-dashboard server.port=2259
运行程序,访问http://127.0.0.1:2259/hystrix
再启动ribbon-consumer(eureka-server,computer-service),
访问ribbon-consumer的http://127.0.0.1:2250/hystrix.stream,会打印大量的监控端点信心,如下所示:
四、Hystrix Dashboard图形展示
将上面http://127.0.0.1:2250/hystrix.stream(ribbon-consumer项目的url)的url填入dashboard主页里的文本框内,再点击monitor stream结果:
五、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-hystrix</artifactId> </dependency>
spring-boot-starter-actuator监控模块以开启监控相关的断点
spring-cloud-starter-hystrix并确保引入断路器的依赖
六、Hystrix Dashboard功能介绍
6.1、在主页中我们可以知道有3种监控方式:
默认的集群监控:通过URL http://turbine-hostname:port/turbine.stream开启,实现对默认集群的监控。指定的集群监控:通过URL http://turbine-hostname:port/turbine.stream?cluster=[clusterName]开启,实现对clusterName的监控。
单体应用监控:通过URL http://hystrix-app:port/hystrix.stream开启,实现对某个具体的服务监控。
6.2、首页中还有2个参数:
Delay:采集时间间隔默认为2000毫秒。Title:监控图上面的标题,自定义就好。
6.2、监控页面各元素的具体意义:
6.2.1、一个实心圆和一条曲线
实心圆:实心圆通过颜色表示健康状态,健康度从绿色、黄色、橙色、红色递减。
实心圆大小,表示流量。
曲线:记录2分钟内流量的相对变化,表现出流量的升降趋势。
6.2.2、其他指标
相关文章推荐
- 服务容错保护断路器Hystrix之四:turbine集群监控
- 服务容错保护断路器Hystrix之八:Hystrix资源隔离策略
- 服务容错保护断路器Hystrix之二:Hystrix工作流程解析
- 服务容错保护断路器Hystrix之一:入门介绍
- Spring Cloud架构教程 (十六)服务容错保护(Hystrix断路器)【Dalston版】
- [java]微服务架构连载No4 Hystrix+Dashboard+Turbine实现断路器(限流,超时,异常...)和服务监控
- Spring Cloud构建微服务架构:服务容错保护(Hystrix断路器)
- springcloud微服务四:服务容错保护Hystrix断路器
- Spring Cloud Spring Boot mybatis 企业分布式微服务云(九)服务容错保护(Hystrix断路器)【Dalston版】
- 服务容错保护断路器Hystrix之六:缓存功能的使用
- Spring Cloud构建微服务架构:服务容错保护(Hystrix断路器)【Dalston版】
- 8.Spring Cloud:服务容错保护(Hystrix断路器)【Dalston版】
- 服务容错保护断路器Hystrix之七:做到自动降级
- Spring Cloud Spring Boot mybatis 企业分布式微服务云(九)服务容错保护(Hystrix断路器)【Dalston版】
- spring cloud Hystrix 服务容错保护监控(二)
- 服务容错保护断路器Hystrix之五:配置
- Spring Cloud构建微服务架构:服务容错保护(Hystrix断路器)【Dalston版】
- 服务容错保护断路器Hystrix之六:服务熔断和服务降级
- spring cloud 使用Hystrix 实现断路器进行服务容错保护的方法
- Spring Boot + Spring Cloud 构建微服务系统(五):熔断监控面板(Hystrix Dashboard)