一,介绍
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
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springcloud1</artifactId>
<groupId>com.drhj</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.drhj</groupId>
<artifactId>sp07-hystrix-dashboard</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sp07-hystrix-dashboard</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</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 刷新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依赖
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springcloud1</artifactId>
<groupId>com.drhj</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.drhj</groupId>
<artifactId>sp08-turbine</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sp08-turbine</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4.配置application.yml文件
spring:
application:
name: turbine
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
查看断路器仪表盘
|