Skip to content

Commit 2308a44

Browse files
committed
feat/添加监控微服务
1 parent 1df9de9 commit 2308a44

File tree

16 files changed

+358
-6
lines changed

16 files changed

+358
-6
lines changed

pmhub-auth/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@
5353
<artifactId>spring-boot-starter-actuator</artifactId>
5454
</dependency>
5555

56-
<!-- PmHub Base Core-->
57-
<dependency>
58-
<groupId>com.laigeoffer.pmhub-cloud</groupId>
59-
<artifactId>pmhub-base-core</artifactId>
60-
</dependency>
6156

6257
<!-- PmHub Base Core-->
6358
<dependency>

pmhub-auth/src/main/resources/bootstrap.yml

+5
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ spring:
2323
# 共享配置
2424
shared-configs:
2525
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
26+
27+
# 实时log配置,可在http://localhost:6888/ 监控中心查看实时日志
28+
logging:
29+
file:
30+
name: logs/${spring.application.name}/info.log

pmhub-gateway/src/main/resources/bootstrap.yml

+5
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ spring:
3838
groupId: DEFAULT_GROUP
3939
data-type: json
4040
rule-type: gw-flow
41+
42+
# 实时log配置,可在http://localhost:6888/ 监控中心查看实时日志
43+
logging:
44+
file:
45+
name: logs/${spring.application.name}/info.log

pmhub-modules/pmhub-gen/src/main/resources/bootstrap.yml

+5
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ spring:
2323
# 共享配置
2424
shared-configs:
2525
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
26+
27+
# 实时log配置,可在http://localhost:6888/ 监控中心查看实时日志
28+
logging:
29+
file:
30+
name: logs/${spring.application.name}/info.log

pmhub-modules/pmhub-job/src/main/resources/bootstrap.yml

+5
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ spring:
2323
# 共享配置
2424
shared-configs:
2525
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
26+
27+
# 实时log配置,可在http://localhost:6888/ 监控中心查看实时日志
28+
logging:
29+
file:
30+
name: logs/${spring.application.name}/info.log

pmhub-modules/pmhub-project/src/main/resources/bootstrap.yml

+5
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ spring:
2323
# 共享配置
2424
shared-configs:
2525
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
26+
27+
# 实时log配置,可在http://localhost:6888/ 监控中心查看实时日志
28+
logging:
29+
file:
30+
name: logs/${spring.application.name}/info.log

pmhub-modules/pmhub-system/src/main/resources/bootstrap.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ spring:
2222
file-extension: yml
2323
# 共享配置
2424
shared-configs:
25-
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
25+
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
26+
27+
# 实时log配置,可在http://localhost:6888/ 监控中心查看实时日志
28+
logging:
29+
file:
30+
name: logs/${spring.application.name}/info.log

pmhub-modules/pmhub-workflow/src/main/resources/bootstrap.yml

+5
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ spring:
2323
# 共享配置
2424
shared-configs:
2525
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
26+
27+
# 实时log配置,可在http://localhost:6888/ 监控中心查看实时日志
28+
logging:
29+
file:
30+
name: logs/${spring.application.name}/info.log

pmhub-monitor/pom.xml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.laigeoffer.pmhub-cloud</groupId>
8+
<artifactId>pmhub</artifactId>
9+
<version>0.0.1</version>
10+
</parent>
11+
12+
<artifactId>pmhub-monitor</artifactId>
13+
14+
<description>
15+
pmhub-monitor 监控中心
16+
</description>
17+
18+
<properties>
19+
<maven.compiler.source>8</maven.compiler.source>
20+
<maven.compiler.target>8</maven.compiler.target>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
</properties>
23+
24+
<dependencies>
25+
26+
<!-- SpringBoot Admin -->
27+
<dependency>
28+
<groupId>de.codecentric</groupId>
29+
<artifactId>spring-boot-admin-starter-server</artifactId>
30+
<version>${spring-boot-admin.version}</version>
31+
</dependency>
32+
33+
<!-- SpringCloud Alibaba Nacos -->
34+
<dependency>
35+
<groupId>com.alibaba.cloud</groupId>
36+
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
37+
</dependency>
38+
39+
<!-- SpringCloud Alibaba Nacos Config -->
40+
<dependency>
41+
<groupId>com.alibaba.cloud</groupId>
42+
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
43+
</dependency>
44+
45+
<!-- Spring Cloud Config Client,用于配置的动态刷新 -->
46+
<dependency>
47+
<groupId>org.springframework.cloud</groupId>
48+
<artifactId>spring-cloud-starter-bootstrap</artifactId>
49+
</dependency>
50+
51+
<!-- SpringCloud Alibaba Sentinel -->
52+
<dependency>
53+
<groupId>com.alibaba.cloud</groupId>
54+
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
55+
</dependency>
56+
57+
<!-- SpringBoot Web -->
58+
<dependency>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-starter-web</artifactId>
61+
</dependency>
62+
63+
<!-- Spring Security -->
64+
<dependency>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter-security</artifactId>
67+
</dependency>
68+
69+
</dependencies>
70+
71+
<build>
72+
<finalName>${project.artifactId}</finalName>
73+
<plugins>
74+
<plugin>
75+
<groupId>org.springframework.boot</groupId>
76+
<artifactId>spring-boot-maven-plugin</artifactId>
77+
<executions>
78+
<execution>
79+
<goals>
80+
<goal>repackage</goal>
81+
</goals>
82+
</execution>
83+
</executions>
84+
</plugin>
85+
</plugins>
86+
</build>
87+
88+
89+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.laigeoffer.pmhub.monitor;
2+
3+
import de.codecentric.boot.admin.server.config.EnableAdminServer;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.cloud.context.config.annotation.RefreshScope;
7+
8+
/**
9+
* @author canghe
10+
* @description 监控中心
11+
* @create 2024-05-16-16:22
12+
*/
13+
@EnableAdminServer
14+
@SpringBootApplication
15+
@RefreshScope
16+
public class PmHubMonitorApplication {
17+
public static void main(String[] args) {
18+
SpringApplication.run(PmHubMonitorApplication.class, args);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.laigeoffer.pmhub.monitor.config;
2+
3+
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
4+
import de.codecentric.boot.admin.server.domain.events.InstanceEvent;
5+
import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent;
6+
import de.codecentric.boot.admin.server.notify.AbstractStatusChangeNotifier;
7+
import org.springframework.stereotype.Component;
8+
import reactor.core.publisher.Mono;
9+
10+
/**
11+
* @author canghe
12+
* @description 通知发送配置
13+
* @create 2024-05-16-17:32
14+
*/
15+
@Component
16+
public class PmHubStatusChangeNotifier extends AbstractStatusChangeNotifier {
17+
public PmHubStatusChangeNotifier(InstanceRepository repository) {
18+
super(repository);
19+
}
20+
21+
@Override
22+
protected Mono<Void> doNotify(InstanceEvent event,
23+
de.codecentric.boot.admin.server.domain.entities.Instance instance) {
24+
return Mono.fromRunnable(() -> {
25+
if (event instanceof InstanceStatusChangedEvent) {
26+
String status = ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus();
27+
switch (status) {
28+
// 健康检查没通过
29+
case "DOWN":
30+
System.out.println("发送 健康检查没通过 的通知!");
31+
break;
32+
// 服务离线
33+
case "OFFLINE":
34+
System.out.println("发送 服务离线 的通知!");
35+
break;
36+
// 服务上线
37+
case "UP":
38+
System.out.println("发送 服务上线 的通知!");
39+
break;
40+
// 服务未知异常
41+
case "UNKNOWN":
42+
System.out.println("发送 服务未知异常 的通知!");
43+
break;
44+
default:
45+
break;
46+
}
47+
}
48+
});
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.laigeoffer.pmhub.monitor.config;
2+
3+
import de.codecentric.boot.admin.server.config.AdminServerProperties;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7+
import org.springframework.security.web.SecurityFilterChain;
8+
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
9+
10+
/**
11+
* 监控权限配置
12+
*
13+
* @author ruoyi
14+
*/
15+
@EnableWebSecurity
16+
public class WebSecurityConfigurer
17+
{
18+
private final String adminContextPath;
19+
20+
public WebSecurityConfigurer(AdminServerProperties adminServerProperties)
21+
{
22+
this.adminContextPath = adminServerProperties.getContextPath();
23+
}
24+
25+
@Bean
26+
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception
27+
{
28+
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
29+
successHandler.setTargetUrlParameter("redirectTo");
30+
successHandler.setDefaultTargetUrl(adminContextPath + "/");
31+
32+
return httpSecurity
33+
.headers().frameOptions().disable()
34+
.and().authorizeRequests()
35+
.antMatchers(adminContextPath + "/assets/**"
36+
, adminContextPath + "/login"
37+
, adminContextPath + "/actuator/**"
38+
, adminContextPath + "/instances/**"
39+
).permitAll()
40+
.anyRequest().authenticated()
41+
.and()
42+
.formLogin().loginPage(adminContextPath + "/login")
43+
.successHandler(successHandler).and()
44+
.logout().logoutUrl(adminContextPath + "/logout")
45+
.and()
46+
.httpBasic().and()
47+
.csrf()
48+
.disable()
49+
.build();
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Application Version: ${spring-boot.version}
2+
Spring Boot Version: ${spring.application.name}
3+
4+
_ _ _ _
5+
| | | | (_) |
6+
_ __ _ __ ___ | |__ _ _| |__ ______ _ __ ___ ___ _ __ _| |_ ___ _ __
7+
| '_ \| '_ ` _ \| '_ \| | | | '_ \______| '_ ` _ \ / _ \| '_ \| | __/ _ \| '__|
8+
| |_) | | | | | | | | | |_| | |_) | | | | | | | (_) | | | | | || (_) | |
9+
| .__/|_| |_| |_|_| |_|\__,_|_.__/ |_| |_| |_|\___/|_| |_|_|\__\___/|_|
10+
| |
11+
|_|
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Tomcat
2+
server:
3+
port: 6888
4+
5+
# Spring
6+
spring:
7+
application:
8+
# 应用名称
9+
name: pmhub-monitor
10+
profiles:
11+
# 环境配置
12+
active: dev
13+
cloud:
14+
nacos:
15+
discovery:
16+
# 服务注册地址
17+
server-addr: 127.0.0.1:8848
18+
config:
19+
# 配置中心地址
20+
server-addr: 127.0.0.1:8848
21+
# 配置文件格式
22+
file-extension: yml
23+
# 共享配置
24+
shared-configs:
25+
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

0 commit comments

Comments
 (0)