Dashboard监控页面和Zuul路由网关
Dashboard监控页面
dashboard监控功能:我们需要前端页面能够监控提供者provider8001的工作状态
对dashboard监控页面的介绍:
1.在客户端导依赖
<?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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.example</groupId> <artifactId>springcloud</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.lian</groupId> <artifactId>springcloud-consumer-hystrix-dashboard</artifactId> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <version>2.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.example</groupId> <artifactId>springcloud-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> <version>2.1.2.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix-dashboard --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> <version>2.1.3.RELEASE</version> </dependency> </dependencies> </project>
2.配置文件
3.主启动类开启支持注解
4.在provider8001也要确保存在它能被监控的依赖actuator
5.在provider8001要增加一个可以供前端访问的servlet,同时入到springboot容器中
6.测试
可以先访问8001端口下面的方法看看能不能调到底层数据,可以再
访问:http://localhost:9001/hystrix 出现下面页面
我们每刷新一次,监控页面就有更新
Zuul路由网关
目的:为了安全,将前端url访问时真实的ip替换成其他
zuul的使用要注入到eureka中,需要有配置文件,配置文件被spring boot托管
1.导包
<dependencies> <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-zuul --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-zuul</artifactId> <version>2.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <version>2.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
2.配置文件
3.主启动类
4.测试