我是靠谱客的博主 害羞萝莉,最近开发中收集的这篇文章主要介绍九、Hystrix Dashboard,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

一、简介

Hystrix是由Netflix开源的一个延迟和容错库,实现熔断器。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是一个图形化界面,支持数据监控。

 

二、搭建熔断器服务

<?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">
    <parent>
        <artifactId>mo-cloud</artifactId>
        <groupId>com.mo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <description>Hystrix Dashboard(断路器:Hystrix 仪表盘)只监控一个实例</description>

    <artifactId>hystrix-dashboard</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- 服务监控的依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <!-- 熔断依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>

        <!-- 断路器仪表盘依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
    </dependencies>

</project>
server:
  # springboot设置随机端口号
  port: 0
eureka:
  client:
    service-url:
      default-zone: http://127.0.0.1:8761/eureka/
  instance:
    # 重写服务的唯一Id,防止多实例对被注册成一个服务
    instance-id: ${spring.application.name}:${random.int}
    # 设置优先使用ip进行注册
    prefer-ip-address: true
spring:
  application:
    name: hystrix-dashboard
# actuator 安全检查开放消息推送刷新
management:
  endpoints:
    web:
      exposure:
        # 开放安全检查的端点
        include: "*"
package com.mo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * EnableHystrixDashboard注解,开启HystrixDashboard,仪表盘监控服务
 * SpringCloudApplication注解,支持服务注册,springboot启动,hystrix熔断
 *
 * @author x.pan
 * @email px5215201314@163.com
 * @date 2020/5/2 16:23
 */
@RestController
@SpringCloudApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {

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


    @GetMapping("/hello")
    @HystrixCommand(fallbackMethod = "helloError")
    public String hello() {
        return "hello";
    }

    /**
     * HystrixCommand 熔断的失败返回方法
     *
     * @return
     */
    public String helloError() {
        return "hello error";
    }

    /**
     * 版本差异:添加actuator端点hystrix.stream
     * <p>
     * 访问地址 http://localhost:xxx/actuator/hystrix.stream
     *
     * @return
     */
    @Bean
    public ServletRegistrationBean hystrixMetricsStreamServlet() {
        ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        registration.addUrlMappings("/actuator/hystrix.stream");
        return registration;
    }
}

三、Hystrix Dashboard演示

1. 访问http://127.0.0.1:49859/hystrix

2. 添加 http://127.0.0.1:49859/actuator/hystrix.stream端点

3. 熔断监控,请求接口http://127.0.0.1:49859/hello 

 

 

 

最后

以上就是害羞萝莉为你收集整理的九、Hystrix Dashboard的全部内容,希望文章能够帮你解决九、Hystrix Dashboard所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部