# update 权限相关
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package com.maibu.memory;
|
||||
|
||||
|
||||
import com.maibu.utils.spring.SpringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
@@ -19,6 +21,8 @@ import java.util.concurrent.TimeUnit;
|
||||
public class SystemMonitor {
|
||||
private final Logger logger = LoggerFactory.getLogger(SystemMonitor.class);
|
||||
|
||||
private ScheduledExecutorService executor = SpringUtils.getBean("scheduledExecutorService");
|
||||
|
||||
// 启动监控任务
|
||||
@PostConstruct
|
||||
public void startMonitoring() {
|
||||
@@ -37,7 +41,6 @@ public class SystemMonitor {
|
||||
|
||||
// 内存监控
|
||||
private void startMemoryMonitor() {
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long totalMemory = runtime.totalMemory() / (1024 * 1024);
|
||||
@@ -59,7 +62,6 @@ public class SystemMonitor {
|
||||
|
||||
// CPU 监控
|
||||
private void startCpuMonitor() {
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
// 使用 OperatingSystemMXBean 获取 CPU 使用率
|
||||
@@ -84,7 +86,6 @@ public class SystemMonitor {
|
||||
|
||||
// 线程监控
|
||||
private void startThreadMonitor() {
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
|
||||
int threadCount = threadBean.getThreadCount();
|
||||
@@ -105,7 +106,6 @@ public class SystemMonitor {
|
||||
|
||||
// 连接数监控
|
||||
private void startConnectionMonitor() {
|
||||
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
executor.scheduleAtFixedRate(() -> {
|
||||
int webSocketCount = MiddleGlobalMemory.onlineSockets.size();
|
||||
int nettyClientCount = MiddleGlobalMemory.nettyClientMap.size();
|
||||
@@ -114,4 +114,5 @@ public class SystemMonitor {
|
||||
webSocketCount, nettyClientCount);
|
||||
}, 1, 5, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user