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

SpringCloud 11 Hystrix Dashboard 流监控

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

SpringCloud 11 Hystrix Dashboard 流监控

11.1 Hystrix Dashboard 流监控
  1. 新建 一个 springcloud-consumer-hystrix-dashboard

需要多加一个 Hystrix 的依赖 和 Hystrix-dashboard 依赖



    
        springcloud
        top.muquanyu
        1.0-SNAPSHOT
    
    4.0.0

    springcloud-consumer-hystrix-dashboard

    
        8
        8
    

    
        
            top.muquanyu
            springcloud-api
            1.0-SNAPSHOT
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-devtools
        
        
            org.springframework.cloud
            spring-cloud-starter-eureka
            1.4.7.RELEASE
        

        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix
            2.2.10.RELEASE
        

        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-hystrix-dashboard
            2.2.10.RELEASE
        
    

  1. 配置 application.yaml
server:
  port: 9001
  
hystrix:
  dashboard:
    proxy-stream-allow-list: "*"
  1. 使用 @EnableHystrixDashboard 注解
package top.muquanyu.springcloud;

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

@SpringBootApplication
@EnableHystrixDashboard // 开启 Dashboard
public class DeptConsumerDashboard_9001 {
    public static void main(String[] args) {
        SpringApplication.run(DeptConsumerDashboard_9001.class,args);
    }
}


4. 访问 http://localhost:9001/hystrix


5. 在 springcloud-provider-dept-hystrix-8001 中 新增 一个 Servlet

package top.muquanyu.springcloud;

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.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableHystrix // 添加 对 Hystrix 的支持
public class DeptProviderHystrix_8001 {
    public static void main(String[] args) {
        SpringApplication.run(DeptProviderHystrix_8001.class,args);
    }


    @Bean
    // 增加 一个 Servlet
    public ServletRegistrationBean hystrixMetricsStreamServlet(){

        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());

        servletRegistrationBean.addUrlMappings("/actuator/hystrix.stream");

        return servletRegistrationBean;
    }
}

访问 http://localhost:8001/actuator/hystrix.stream

切记:hystrix 监控,肯定监控的是 熔断 的 服务呀。


6. 使用 http://localhost:9001/hystrix 监控 8001 服务

如果 一直报错 jdbc 的 java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not all,则 在 url 那里 添加 allowPublicKeyRetrieval=true 即可解决问题。

server:
  port: 8001

mybatis:
  type-aliases-package: top.muquanyu.springcloud.pojo
  config-location: classpath:mybatis/mybatis-config.xml
  mapper-locations: classpath:mybatis/mapper/*.xml

#spring 的配置
spring:
  application:
    name: springcloud-provider-dept
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/db01?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
    username: root
    password: 123123
#Eureka 的配置,只需要配置 服务 注册到 哪里就行了
eureka:
  client:
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka
  instance:
    instance-id: springcloud-provider-hystrix-dept8001 # 这个更改的就是 Status 的描述
    perfer-ip-address: true

# info 配置
info:
  app.name: MQy-springcloud
  company.name: MQy

management:
  endpoints:
    web:
      exposure:
        include: "*"
  info:
    env:
      enabled: true



如果 这个上面的页面,一直 显示 ping 则 先去 请求一下 服务。则就会 显示 正常的数据页面了。

如下:我们可以 直接 对 这个 流 进行监控!

然后,只要 发送 一个 请求,使用 一次 服务,我们这里 就会 有 监控 在 信息在变动!




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

版权所有 (c)2021-2022 wk8.com.cn

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