【Sping Cloud】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
没添加依赖前
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第1张图片
添加查看所有的依赖

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

查看
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第2张图片
当我们启用item服务,
访问http://localhost:3001/actuator/hystrix.stream
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第3张图片

三,搭建Hystrix dashboard

1.新建模块

新建spring boot 项目
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第4张图片
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第5张图片
这里不添加任何依赖

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


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springcloud1artifactId>
        <groupId>com.drhjgroupId>
        <version>0.0.1-SNAPSHOTversion>
    parent>
    <modelVersion>4.0.0modelVersion>

    <groupId>com.drhjgroupId>
    <artifactId>sp07-hystrix-dashboardartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>sp07-hystrix-dashboardname>
    <description>Demo project for Spring Bootdescription>
    <properties>
        <java.version>1.8java.version>
    properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starterartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboardartifactId>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>

project>

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
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第6张图片
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第7张图片
刷新http://localhost:3001/item-service/t45t4?token=100,查看服务波动
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第8张图片
红色的0表示请求失败数为0
Circuit表示熔断器的状态
使用压力测试工具测试【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第9张图片

四,Turbine

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

1.启动网关Zuul高可用

【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第10张图片
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第11张图片

2.新建模块sp08–turbine

创建springboot的moudle
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第12张图片
添加依赖
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第13张图片

3.配置pom.xml文件

添加eureka client, turbine依赖


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springcloud1artifactId>
        <groupId>com.drhjgroupId>
        <version>0.0.1-SNAPSHOTversion>
    parent>
    <modelVersion>4.0.0modelVersion>

    <groupId>com.drhjgroupId>
    <artifactId>sp08-turbineartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>sp08-turbinename>
    <description>Demo project for Spring Bootdescription>
    <properties>
        <java.version>1.8java.version>
    properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-netflix-turbineartifactId>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>

project>

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.测试

启动服务
分别运行两个网关
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第14张图片
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第15张图片
访问 合并日志版本:http://localhost:5001/turbine.stream
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第16张图片

查看断路器仪表盘
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第17张图片
【Sping Cloud】04--Hystrix dashboard 断路器仪表盘_第18张图片

你可能感兴趣的:(SpringCloud,dashboard,spring,cloud,netflix)