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

【Sping Cloud Netflix】04--Hystrix dashboard 断路器仪表盘

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

【Sping Cloud Netflix】04--Hystrix dashboard 断路器仪表盘

一,介绍

1)Hystrix数据监控仪表盘
2)Hystrix日志,是通过Actuator工具来暴露出来

二,Actuator 1.介绍

springboot 提供的一个项目指标工具,可以通过Actuator获取项目的各种日志数据

  • 健康状态
  • spring容器中所有的对象
  • spring mvc映射的所有路径
  • jvm堆内存镜像
2.依赖

Zuul中默认含有Actuator,所以无需添加

3.暴露日志设置
m.e.w.e.i = "*" #暴露所有日志
m.e.w.e.i = health #暴露健康状态日志
m.e.w.e.i = health,beans,mappings,hytrix,stream #暴露多种日志
4.查看日志

http://localhost:3001/actuator
没添加依赖前

添加查看所有的依赖

management:
  endpoints:
    web:
      exposure:
        include: "*"

查看

当我们启用item服务,
访问http://localhost:3001/actuator/hystrix.stream

三,搭建Hystrix dashboard 1.新建模块

新建spring boot 项目


这里不添加任何依赖

2.添加依赖 Hystrix dashboard,配置pom.xml


    
        springcloud1
        com.drhj
        0.0.1-SNAPSHOT
    
    4.0.0

    com.drhj
    sp07-hystrix-dashboard
    0.0.1-SNAPSHOT
    sp07-hystrix-dashboard
    Demo project for Spring Boot
    
        1.8
    
    
        
            org.springframework.boot
            spring-boot-starter
        

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

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


3.yml配置

允许抓取的服务器列表:localhost:…

server:
  port: 4001
hystrix:
  dashboard:
    proxy-stream-allow-list: 
      - localhost
4.启动类添加注解
package com.drhj.sp07;

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

@EnableHystrixDashboard
@SpringBootApplication
public class Sp07HystrixDashboardApplication {

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

}
5.测试

启动项目
访问http://localhost:4001/hystrix


刷新http://localhost:3001/item-service/t45t4?token=100,查看服务波动

红色的0表示请求失败数为0
Circuit表示熔断器的状态
使用压力测试工具测试

四,Turbine

聚合多台服务器的日志数据,提供给仪表盘显示

1.启动网关Zuul高可用


2.新建模块sp08–turbine

创建springboot的moudle

添加依赖

3.配置pom.xml文件

添加eureka client, turbine依赖



    
        springcloud1
        com.drhj
        0.0.1-SNAPSHOT
    
    4.0.0

    com.drhj
    sp08-turbine
    0.0.1-SNAPSHOT
    sp08-turbine
    Demo project for Spring Boot
    
        1.8
    
    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-turbine
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


4.配置application.yml文件
spring:
  application:
    name: turbine
# 2001 eureka
# 3001 zuul
# 4001 hystrix dashboard    
server:
  port: 5001
eureka:
  client:
    service-url: 
      defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
turbine:
  app-config: zuul     #多个的话使用,号隔开
  cluster-name-expression: new String("default")
5.启动类添加注解@EnableTurine
package com.drhj.sp08;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@EnableTurbine
@SpringBootApplication
public class Sp08TurbineApplication {

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

}
6.测试

启动服务
分别运行两个网关


访问 合并日志版本:http://localhost:5001/turbine.stream

查看断路器仪表盘

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

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

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