mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: add monitor module
This commit is contained in:
parent
ad1a7227d6
commit
5080796c6f
@ -21,6 +21,7 @@
|
|||||||
<module>powerjob-server-extension</module>
|
<module>powerjob-server-extension</module>
|
||||||
<module>powerjob-server-migrate</module>
|
<module>powerjob-server-migrate</module>
|
||||||
<module>powerjob-server-core</module>
|
<module>powerjob-server-core</module>
|
||||||
|
<module>powerjob-server-monitor</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
||||||
@ -56,6 +57,11 @@
|
|||||||
<artifactId>powerjob-server-common</artifactId>
|
<artifactId>powerjob-server-common</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>tech.powerjob</groupId>
|
||||||
|
<artifactId>powerjob-server-monitor</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>tech.powerjob</groupId>
|
<groupId>tech.powerjob</groupId>
|
||||||
<artifactId>powerjob-server-extension</artifactId>
|
<artifactId>powerjob-server-extension</artifactId>
|
||||||
|
28
powerjob-server/powerjob-server-monitor/pom.xml
Normal file
28
powerjob-server/powerjob-server-monitor/pom.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?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>powerjob-server</artifactId>
|
||||||
|
<groupId>tech.powerjob</groupId>
|
||||||
|
<version>4.1.0</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>powerjob-server-monitor</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>tech.powerjob</groupId>
|
||||||
|
<artifactId>powerjob-server-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,22 @@
|
|||||||
|
package tech.powerjob.server.monitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监控事件
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2022/9/6
|
||||||
|
*/
|
||||||
|
public interface Event {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监控事件的类型
|
||||||
|
* @return 监控类型
|
||||||
|
*/
|
||||||
|
String type();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监控事件的内容
|
||||||
|
* @return 监控事件的内容
|
||||||
|
*/
|
||||||
|
String message();
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package tech.powerjob.server.monitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监视器
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2022/9/6
|
||||||
|
*/
|
||||||
|
public interface Monitor {
|
||||||
|
/**
|
||||||
|
* 记录监控事件
|
||||||
|
* 请注意该方法务必异步不阻塞!!!
|
||||||
|
* @param event 事件
|
||||||
|
*/
|
||||||
|
void record(Event event);
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package tech.powerjob.server.monitor.monitors;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import tech.powerjob.server.monitor.Event;
|
||||||
|
import tech.powerjob.server.monitor.Monitor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务端监视器
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2022/9/6
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class ServerMonitor implements Monitor {
|
||||||
|
|
||||||
|
private final List<Monitor> monitors = Lists.newLinkedList();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ServerMonitor(List<Monitor> monitors) {
|
||||||
|
monitors.forEach(m -> {
|
||||||
|
if (m == this) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.info("[ServerMonitor] register monitor: {}", m.getClass().getName());
|
||||||
|
this.monitors.add(m);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void record(Event event) {
|
||||||
|
monitors.forEach(m -> m.record(event));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package tech.powerjob.server.monitor.monitors.impl;
|
||||||
|
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import tech.powerjob.server.monitor.Event;
|
||||||
|
import tech.powerjob.server.monitor.Monitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统默认实现——基于日志的监控监视器
|
||||||
|
* 需要接入方自行基于类 ELK 系统采集
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2022/9/6
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class LogMonitor implements Monitor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void record(Event event) {
|
||||||
|
LoggerFactory.getLogger(event.type()).info(event.message());
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,10 @@
|
|||||||
<groupId>tech.powerjob</groupId>
|
<groupId>tech.powerjob</groupId>
|
||||||
<artifactId>powerjob-server-common</artifactId>
|
<artifactId>powerjob-server-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>tech.powerjob</groupId>
|
||||||
|
<artifactId>powerjob-server-monitor</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>tech.powerjob</groupId>
|
<groupId>tech.powerjob</groupId>
|
||||||
<artifactId>powerjob-server-persistence</artifactId>
|
<artifactId>powerjob-server-persistence</artifactId>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user