栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringCloud中集成Hystrix后通过Dashboard实现图形化监控实现

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringCloud中集成Hystrix后通过Dashboard实现图形化监控实现

场景

SpringCloud中集成Hystrix实现服务降级(从实例入手):

SpringCloud中集成Hystrix实现服务降级(从实例入手)_霸道流氓气质的博客-CSDN博客

SpringCloud中集成Hystrix实现熔断(从实例入手):

SpringCloud中集成Hystrix实现熔断(从实例入手)_霸道流氓气质的博客-CSDN博客

在上面集成Hystrix实现服务降级与熔断的基础上,怎样搭建可视化监控平台。

注:

博客:
霸道流氓气质的博客_CSDN博客-C#,架构之路,SpringBoot领域博主
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

1、与上面流程一样新建子模块cloud-consumer-hystrix-dashboard9002

pom文件中添加依赖

    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix-dashboard
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
    

2、新建并修改application.yml

server:
  port: 9002

3、新建启动类并添加@EnableHystrixDashboard注解

package com.badao.springclouddemo;

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


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

4、启动服务,访问

http://127.0.0.1:9002/hystrix

5、比如这里要监控服务提供者8001

则在输入框中输入

http://127.0.0.1:8001/hystrix.stream

然后Delay输入2000,Title输入T3,点击Monitor Stream

此时DashBoard提示 Unable to connect to Command Metric Stream

这是因为springcloud升级之后的bug,ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream",

所以在8001主启动类中添加配置

    @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;
    }

完整启动类

package com.badao.springclouddemo;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;


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

    
    @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;
    }
}

然后此时重新对8001进行监控,并调用8001的接口

还可以触发熔断,可以在面板中看到Circuit即为显示熔断器是否开启

6、图形化怎么看

首先7种颜色的个数分别对应7种状态

圆圈代表的意思

它通过颜色的变化代表了实例的健康程度,它的健康度从绿色<黄色<橙色<红色递减。

它的大小也会根据实例的请求流量发生变化,流量越大该圆越大。

所以通过该实心圆的展示,就可以在大量的实例中快速发现故障实例和高压力实例。

整图说明

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/933004.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号