java怎么断路_13、如何使用断路器监控Hystrix Dashboard

公众号: java乐园

在微服务架构中如何去监控服务的状态是否正常,非常重要。为例保证微服务的可用性,防止程序断路器模型。运维人员需要一个友好的程序来监控微服务的状态, Hystrix Dashboard作为断路器监控的一个重要组件,提供了数据监控及非常友好的图形化界面,方便运维人员对服务进行监控;,通过界面反馈的信息可以快速发现系统中存在的问题。另外Hystrix Dashboard是一个独立的服务结点,不需要配置任何的注册中心。

1、 新建项目sc-hystrix-dashboard,对用的pom.xml文件如下

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

spring-cloud

sc-hystrix-dashboard

0.0.1-SNAPSHOT

jar

sc-hystrix-dashboard

http://maven.apache.org

org.springframework.boot

spring-boot-starter-parent

2.0.4.RELEASE

org.springframework.cloud

spring-cloud-dependencies

Finchley.RELEASE

pom

import

UTF-8

1.8

1.8

org.springframework.cloud

spring-cloud-starter-netflix-hystrix-dashboard

org.springframework.cloud

spring-cloud-starter-netflix-hystrix

org.springframework.boot

spring-boot-starter-actuator

说明:spring cloud 2.x之后spring-cloud-starter-hystrix-dashboard和spring-cloud-starter-hystrix都标志为过期,具体推荐使用两个依赖请看下面的图片

62c3edabf1fbcc08cbe651406001f590.png

001c11caf4f3f7f407c7485309bbf0f5.png

2、 新建spring boot启动类DashboardApplication.java

package sc.hystrix.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);

}

}

只需添加注解EnableHystrixDashboard,启动Hystrix Dashboard即可

3、 配置Hystrix Dashboard对应的Servlet

package sc.hystrix.dashboard;

import org.springframework.boot.web.servlet.ServletRegistrationBean;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;

@Configuration

public class DashboardServletConfig {

@Bean

public ServletRegistrationBean getDashboardServlet(){

HystrixMetricsStreamServlet servlet = new HystrixMetricsStreamServlet();

ServletRegistrationBean bean = new ServletRegistrationBean(servlet);

bean.setLoadOnStartup(1);

bean.addUrlMappings("/hystrix.stream");

bean.setName("hystrix");

return bean;

}

}

4、 新建配置文件bootstrap.yml

spring:

application:

name: sc-hystrix-dashboard

server:

port: 2001

5、 启动并验证是否启动成功

方法一:查看日志配置的端口2001,在日志中标志启动成功

789a50f6a31a1cc2676d90a639c332c1.png

方法二:从上图标志的1中可以知道可以方法地址:http://127.0.0.1:2001/hystrix

0f1646566a60febc62d0e733802ff7a8.png

6、 分析一下下图中的英文

6e6701c0d76fc4489e563914ee56360f.png

大概的意思是:如果查看默认集群使用第一个url,查看指定集群使用第二个url,单个应用监控使用最后一个

7、 在url中输入http://127.0.0.1:2001/hystrix.stream

2f043bd9841ae298b9ffefa4dc8c95a3.png

然后点击Monitor Stream按钮

a5bda0b19c140c2a0da394584e2ac3ca.png

或者访问http://localhost:2001/hystrix.stream也会不断的显示ping

e5a859618f1f4139693ffeb0f0ed9207.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值