码迷,mamicode.com
首页 > 编程语言 > 详细

springCloud(十二) hystrix dashboard

时间:2020-06-26 12:40:07      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:open   one   port   serve   href   turn   artifact   ping   board   

被监控端

1: 在微服务上pom.xml 引入依赖

        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-metrics-event-stream</artifactId>
            <version>1.5.18</version>
        </dependency>

2: 在application.java 中 引入bean

package com.itlaoqi.springcloud.memberserviceopenfeign;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import feign.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableFeignClients
public class MemberServiceOpenfeignApplication {

    // 被引入的bean
    @Bean
    public ServletRegistrationBean hystrixServlet(){
        HystrixMetricsStreamServlet servlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        registrationBean.setLoadOnStartup(1);
        return registrationBean;

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

2: 创建监控工程 dashboard 监控

1: pom.xml

        <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-dashboard</artifactId>
        </dependency>

2: application.yml文件

server:
  port: 9100
spring:
  application:
    name: hystrix-dashboard
eureka:
  client:
    service-url:
      defaultZone:
        http://localhost:8761/eureka

3: 在java 类上开启

package com.itlaoqi.springcloud.hystrix.dashboard.dashboardservice;

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

@SpringBootApplication
@EnableHystrixDashboard
public class DashboardServiceApplication {

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

}

4: 开始演示

在 浏览器 输入 http://localhost:9100/hystrix
技术图片

技术图片

注意:springboot2.2.x, hystrix-dashboard监控页面一直显示loading的问题 (https://blog.csdn.net/weixin_43493520/article/details/106646860?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3.nonecase)
我的其他微服务 使用的是 2.3.x版本 。但是2.3.X 版本的 dashboard 前端代码有问题。所以该用2.1.x 版本的dashboard 。使用正常

springCloud(十二) hystrix dashboard

标签:open   one   port   serve   href   turn   artifact   ping   board   

原文地址:https://www.cnblogs.com/guhualin/p/13194266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!