概述
仪表盘就是为了监控的。监控什么? 当然是我们断路器服务的并发量、请求率、错误率等信息,为了更好的,方便我们对服务接口进行测试和排查。架构如下:
使用:
引入响应的jar包:
spring-cloud-starter-hystrix-dashboard;
并且所要监控的服务必须依赖: spring-boot-starter-actuator这个jar才可以监控hystrix.stream 并且启用仪表盘注解配置:@EnableHystrixDashboard 我们通过访问:http://localhost:2001/hystrix即可看到流量监控台: 在下面输入框输入所要监控的服务地址即可(也就是hystrix.stream):
代码实现
@EnableHystrixDashboard
package com.zx.dt2b;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@EnableHystrixDashboard
@EnableDiscoveryClient
@SpringBootApplication //SpringBoot 核心基础配置
@EnableAutoConfiguration //使用SpringBoot 自动配置
public class DashboardApplication {
//数据查看地址: http://localhost:7003/hystrix.stream
//监控台访问地址: http://localhost:2001/hystrix
//在输入框中输入: 数据查看地址后可以看到流量监控
//查询集群状态则需要输入turbine的地址: http://localhost:3000/turbine.stream
public static void main(String[] args) {
SpringApplication.run(DashboardApplication.class, args);
}
}
配置文件:
spring:
application:
name: hystrix-dashboard
server:
context-path: /
port: 2001
#配置注册服务发现中心的地址
eureka:
client:
service-url:
defaultZone: http://eureka1:8001/eureka/
maven:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>com.zx.dt2b.erp</artifactId>
<groupId>com.zx.dt2b.erp</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dashboard</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<!-- <version>Dalston.SR1</version> -->
<version>Edgware.SR4</version>
<!-- <version>Finchley.SR1</version> -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
界面:
学习:https://github.com/Netflix/Hystrix/wiki
//数据查看地址: http://localhost:7003/hystrix.stream
//监控台访问地址: http://localhost:2001/hystrix
//在输入框中输入: 数据查看地址后可以看到流量监控
Hystrix turbine 集群监控:
我们已经学会了如何去使用dashboard监控一个断路器所在的服务,那么对于集群的情况,我们光靠dashbroad是不行的,这里需要引用一个收集组件turbine进行汇总数据,最后流入到我们的监控台(dashboard)中去,引入spring-cloud-starter-turbine依赖,并添加注解@EnableTurbine在我们的项目中,最后我们需要对turbine的yml文件进行相关配置。
代码实现:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>com.zx.dt2b.erp</artifactId>
<groupId>com.zx.dt2b.erp</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>turbine</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<!-- <version>Dalston.SR1</version> -->
<version>Edgware.SR4</version>
<!-- <version>Finchley.SR1</version> -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
主入口:
package com.zx.dt2b;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
@EnableTurbine
@EnableDiscoveryClient
@SpringBootApplication //SpringBoot 核心基础配置
@EnableAutoConfiguration //使用SpringBoot 自动配置
public class TurbineApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}
配置文件:
spring:
application:
name: hystrix-turbine
server:
port: 3000
management:
port: 3001
turbine:
app-config: consumer-service #指定需要收集监控信息的服务名:
cluster-name-expression: "'default'"
combine-host-port: true
eureka:
client:
service-url:
defaultZone: http://eureka1:8001/eureka/
turbine: app-config: consumer-service #指定需要收集监控信息的服务名: cluster-name-expression: "'default'" combine-host-port: true
多个服务可以有相同服务名称
//查询集群状态则需要输入turbine的地址: http://localhost:3000/turbine.stream
最后
以上就是傻傻鞋垫为你收集整理的Spring cloud hystrix 断路器的监控台Hystrix Dashboard的全部内容,希望文章能够帮你解决Spring cloud hystrix 断路器的监控台Hystrix Dashboard所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复