Spring Cloud(Finchley.RELEASE版本)微服务学习实践:4.2Hystrix监控面板-Hystrix Dashboard

环境:

jdk1.8;spring boot2.0.3;spring cloud(Finchley.RELEASE版本);Maven3.3

摘要说明:

Spring Cloud Hystrix Dashboard:收集Hystrix执行过程中的重要指标,整理展示为可视化的数据面板以达到服务监控的作用

步骤:

1.创建hystrixDashboard(Hystrix Dashboard监控面板)子项目

通过SPRING INITIALIZR工具选择Cloud Circuit Breaker:Hystrix DashBoard模块构建hystrixDashBoard子项目引入依赖(pom.xnl):

<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>pers.cc</groupId>
		<artifactId>springCloud</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>hystrixDashboard</artifactId>
	<name>hystrixDashboard</name>
	<description>hystrixDashboard(Hystrix监控面板)</description>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
		</dependency>
	</dependencies>
</project>

2.配置hystrixDashboard

使用@EnableHystrixDashboard注解开启Hystrix Dashboard的Hystrix监控面板配置;

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

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

配置application.properties:

#配置服务名称及端口
spring.application.name=hystrix-dashboard
server.port=6001

3.使用hystrixDashboard

启动服务,浏览器输入http://localhost:6001/hystrix进入监控面板主页面;

此时没有具体的监控信息,需要输入要监控的消费者地址及监控信息的轮询时间和标题;

Hystrix Dashboard共支持三种不同的监控方式:

单体Hystrix 消费者:通过URLhttp://hystrix-app:port/hystrix.stream开启,实现对具体某个服务实例的监控。

默认集群监控:通过URLhttp://turbine-hostname:port/turbine.stream开启,实现对默认集群的监控。

自定集群监控:通过URLhttp://turbine-hostname:port/turbine.stream?cluster=[clusterName]开启,实现对clusterName集群的监控。

本章讲述对单体Hystrix 消费者的监控,后面整合Turbine集群后再说明后两种的监控方式;

这里面需要注意下新版本Hystrix消费者需要在XXApplication.java中指定监控路径;

        // 此配置是为了服务监控而配置,与服务容错本身无关,
	// ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",
	// 只要在自己的项目里配置上下面的servlet就可以了
	@Bean
	public ServletRegistrationBean getServlet() {
		HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
		registrationBean.setLoadOnStartup(1);
		registrationBean.addUrlMappings("/hystrix.stream");
		registrationBean.setName("HystrixMetricsStreamServlet");
		return registrationBean;
	}

先后启动:

服务注册中心(eurekaServer):eureka-server(1001)

服务提供者(eurekaDiscovery):eureka-client(2001)

服务消费者(hystrix):hystrix-consumer(5001)

Hystrix监控面板(hystrixDashboardhystrix-dashboard(6001)

在上述主页面输入http://localhost:5001/hystrix.stream进入监控面板页;多次调用http://localhost:5001/test,http://localhost:5001/test1查看监控面板指标:

下面这张图很好的说明了各个指标的含义:

4.源码地址

github地址:https://github.com/cc6688211/springCloud.git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值