赞
踩
接着上一篇 Spring Cloud实战(二)-注册中心 现在开始搭建监控中心
- <?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">
- <modelVersion>4.0.0</modelVersion>
- <packaging>pom</packaging>
- <modules>
- <module>register-server</module>
- <module>config-server</module>
- <module>monitor-server</module>
- <module>api</module>
- <module>user-server</module>
- <module>order-server</module>
- <module>pay-server</module>
- <module>manage-server</module>
- <module>repository-server</module>
- </modules>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.6.6</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.example</groupId>
- <artifactId>cloud-action</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>cloud-action</name>
- <description>spring cloud 微服务实战</description>
-
- <properties>
- <skipTests>true</skipTests>
- <java.version>1.8</java.version>
- <spring-cloud.version>2021.0.1</spring-cloud.version>
- <spring-boot-admin.version>2.6.3</spring-boot-admin.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <scope>provided</scope> <!-- 作用在编译和测试时,同时没有传递性-->
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-dependencies</artifactId>
- <version>${spring-cloud.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- <dependency>
- <groupId>de.codecentric</groupId>
- <artifactId>spring-boot-admin-dependencies</artifactId>
- <version>${spring-boot-admin.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
- </project>
- <?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>cloud-action</artifactId>
- <groupId>com.example</groupId>
- <version>0.0.1-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>monitor-server</artifactId>
-
- <dependencies>
- <dependency>
- <groupId>de.codecentric</groupId>
- <artifactId>spring-boot-admin-starter-server</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
- </dependency>
- </dependencies>
-
- </project>
- spring:
- application:
- name: monitor-server
- profiles:
- active: single
- #监控配置
- management:
- endpoints:
- web:
- exposure:
- include: "*" #公开所有端点 对于生产,您应该仔细选择要公开的端点.
- endpoint:
- health:
- show-details: always
- info:
- env:
- enabled: true
- ---
- #单机版
- spring:
- config:
- activate:
- on-profile: single
- server:
- port: 2222 #当前eureka-server服务的端口号
- eureka:
- instance:
- lease-renewal-interval-in-seconds: 30 #服务续约(心跳检测)时间,默认30秒
- lease-expiration-duration-in-seconds: 90 #服务剔除时间,默认90秒
- health-check-url-path: /actuator/health
- metadata-map:
- startup: ${random.int} #需要在重启后触发信息和端点更新
- client:
- service-url:
- defaultZone: http://localhost:1111/eureka/ #eureka-client设置eureka-server的地址
- package com.example.monitor;
-
- import de.codecentric.boot.admin.server.config.EnableAdminServer;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
-
- /**
- * @author 86188
- */
- @SpringBootApplication
- @EnableAdminServer //开启监控服务
- public class MonitorApplication {
- public static void main(String[] args) {
- SpringApplication.run(MonitorApplication.class, args);
- }
- }
java -jar monitor-server-0.0.1-SNAPSHOT.jar
可以看到监控信息非常详细
特别说明:
实际开发中监控模块完全可以和eureka注册中心放在一块,只需要配置spring.boot.admin.context-path 以便 Spring Boot Admin Server UI 不会与 Eureka 的 UI 冲突就可以了.此处为了凸显微服务的特性,所以单独作为一个服务.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。