微服务springcloud—使用Hystrix Dashboard可视化监控数据

使用Hystrix Dashboard可视化监控数据

前面讨论了Hystrix的监控,但访问/actuator/hystrix.stream端点获得的数据都是以文字形式展示的。很难通过这些数据,一眼看出系统的运行状态。
可使用Hystrix Dashboard,从让监控数据图形化、可视化。

1.创建一个Maven项目,ArtifactId是microservice-hystrix-dashboard,并添加以下依赖。

		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.4.6.RELEASE</version>
        </dependency>

2.编写启动类,在其动力上添加@EnableHystrixDashboard。

@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {
    @Bean(name="hystrixRegistrationBean")
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }


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

2.0以上版本的spring要加getServlet方法,具体参考链接:
https://blog.csdn.net/ddxd0406/article/details/79643059
https://blog.csdn.net/daihanguang123/article/details/80768221

3.配置文件application.yml

server:
    port: 8030
spring:
    application:
        name: hystrix
#开启断路器功能
feign:
    hystrix:
        enabled: true
management:
    endpoints:
        web:
            exposure:
                include: hystrix.stream

这样,一个简单的Hystrix Dashboard就完成了,有配置可知,我们并没有把Hystrix Dashboard注册到Eureka Server上。

4.测试

1.访问http://localhost:8030/hystrix,可看到Hystrix Dashboard的主页
在这里插入图片描述
2.在上一节测试的基础上,在URL一栏上输入http://localhost:8010/actuator/hystrix.stream,随意设置一个Title,并点击Monitor Stream按钮后
在这里插入图片描述

简单可见,并没有把Hystrix Dashboard注册到Eureka Server上。再生产环境中,也可以把Hystrix Dashboard注册到Eureka Server上,更方便地管理Hystrix Dashboard。

本文大部分内容转载自周立的《Spring Cloud与Docker微服务架构实战》

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值