diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/file/StateController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/file/StateController.java index 32e069e..a44ac80 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/file/StateController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/file/StateController.java @@ -5,6 +5,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.file.model.FileModel; import com.ruoyi.file.model.FileSystemFilter; import com.ruoyi.file.object.ProjectState; +import com.ruoyi.file.object.RuntimeState; import com.ruoyi.file.object.StateMachine; import com.ruoyi.file.service.FileSystemService; import com.ruoyi.file.service.StateService; @@ -94,4 +95,15 @@ public class StateController extends BaseController return AjaxResult.success(); } + /** + * 查询jvm信息 + */ + @ApiOperation("查询jvm信息") + @PreAuthorize("@ss.hasPermi('admin:state:runtime')") + @GetMapping("/runtime") + public AjaxResult runtime() + { + RuntimeState state = stateService.runtimeState(); + return AjaxResult.success(state); + } } diff --git a/ruoyi-file/src/main/java/com/ruoyi/file/object/RuntimeState.java b/ruoyi-file/src/main/java/com/ruoyi/file/object/RuntimeState.java new file mode 100644 index 0000000..0ee9106 --- /dev/null +++ b/ruoyi-file/src/main/java/com/ruoyi/file/object/RuntimeState.java @@ -0,0 +1,126 @@ +package com.ruoyi.file.object; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryMXBean; +import java.lang.management.MemoryPoolMXBean; +import java.lang.management.MemoryUsage; +import java.lang.management.RuntimeMXBean; +import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Data +public final class RuntimeState +{ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") + private Date startTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") + private Date uptime; + private long runDuration; + private String arguments; + + private long heapUsed; + private long heapInit; + private long heapMax; + private long heapCommitted; + + private long nonHeapUsed; + private long nonHeapInit; + private long nonHeapMax; + private long nonHeapCommitted; + + private long threadCount; + private long daemonThreadCount; + private long peakThreadCount; + private long startedThreadCount; + private List threads; + + private List memoryPools; + + @Data + public static class ThreadState + { + private long threadId; + private String threadName; + private String threadState; + private Boolean isCurrent; + } + + @Data + public static class MemoryPoolState + { + private String name; + private String type; + private long memoryUsed = -1; + private long memoryInit = -1; + private long memoryMax = -1; + private long memoryCommitted = -1; + } + + public static RuntimeState capture() + { + RuntimeState state = new RuntimeState(); + RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); + long startTime = runtimeMXBean.getStartTime(); + long uptime = runtimeMXBean.getUptime(); + state.startTime = new Date(startTime); + state.uptime = new Date(startTime + uptime); + state.runDuration = uptime; + state.arguments = String.join(" ", runtimeMXBean.getInputArguments()); + + MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); + MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage(); + state.heapUsed = heapMemoryUsage.getUsed(); + state.heapMax = heapMemoryUsage.getMax(); + state.heapInit = heapMemoryUsage.getInit(); + state.heapCommitted = heapMemoryUsage.getCommitted(); + + MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage(); + state.nonHeapUsed = nonHeapMemoryUsage.getUsed(); + state.nonHeapMax = nonHeapMemoryUsage.getMax(); + state.nonHeapInit = nonHeapMemoryUsage.getInit(); + state.nonHeapCommitted = nonHeapMemoryUsage.getCommitted(); + + ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); + state.threadCount = threadMXBean.getThreadCount(); + state.daemonThreadCount = threadMXBean.getDaemonThreadCount(); + state.peakThreadCount = threadMXBean.getPeakThreadCount(); + state.startedThreadCount = threadMXBean.getTotalStartedThreadCount(); + ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true); + state.threads = new ArrayList<>(); + for(ThreadInfo threadInfo : threadInfos) + { + ThreadState t = new ThreadState(); + t.threadId = threadInfo.getThreadId(); + t.threadName = threadInfo.getThreadName(); + t.threadState = threadInfo.getThreadState().name(); + t.isCurrent = threadInfo.getThreadId() == Thread.currentThread().getId(); + state.threads.add(t); + } + + state.memoryPools = new ArrayList<>(); + List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); + for(MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) + { + MemoryPoolState m = new MemoryPoolState(); + m.name = memoryPoolMXBean.getName(); + m.type = memoryPoolMXBean.getType().name(); + MemoryUsage usage = memoryPoolMXBean.getUsage(); + if(null != usage) + { + m.memoryUsed = usage.getUsed(); + m.memoryMax = usage.getMax(); + m.memoryInit = usage.getInit(); + m.memoryCommitted = usage.getCommitted(); + } + state.memoryPools.add(m); + } + + return state; + } +} diff --git a/ruoyi-file/src/main/java/com/ruoyi/file/object/StateMachine.java b/ruoyi-file/src/main/java/com/ruoyi/file/object/StateMachine.java index 930d010..d305afa 100644 --- a/ruoyi-file/src/main/java/com/ruoyi/file/object/StateMachine.java +++ b/ruoyi-file/src/main/java/com/ruoyi/file/object/StateMachine.java @@ -178,7 +178,7 @@ public final class StateMachine public void GC() { - System.gc(); + //System.gc(); gcCount++; lastGCTime = new Date(); } diff --git a/ruoyi-file/src/main/java/com/ruoyi/file/service/StateService.java b/ruoyi-file/src/main/java/com/ruoyi/file/service/StateService.java index 9bc957e..8abb5aa 100644 --- a/ruoyi-file/src/main/java/com/ruoyi/file/service/StateService.java +++ b/ruoyi-file/src/main/java/com/ruoyi/file/service/StateService.java @@ -5,14 +5,13 @@ import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.file.object.ProjectState; +import com.ruoyi.file.object.RuntimeState; import com.ruoyi.file.object.StateMachine; -import com.ruoyi.file.utils.ProjectUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; -import java.util.Date; import java.util.List; import java.util.Map; @@ -32,9 +31,17 @@ public class StateService return StateMachine.INSTANCE.GetStates(); } + public RuntimeState runtimeState() + { + return RuntimeState.capture(); + } + public long gc() { StateMachine.INSTANCE.GC(); + dump(); + System.gc(); + init(); return StateMachine.INSTANCE.gcCount; } diff --git a/ruoyi-ui/src/api/file/state.js b/ruoyi-ui/src/api/file/state.js index 05b93ea..6b09213 100644 --- a/ruoyi-ui/src/api/file/state.js +++ b/ruoyi-ui/src/api/file/state.js @@ -34,3 +34,10 @@ export function dump() { method: 'post', }) } + +export function runtimeState() { + return request({ + url: '/state/runtime', + method: 'get', + }) +} diff --git a/ruoyi-ui/src/views/file/runtime/index.vue b/ruoyi-ui/src/views/file/runtime/index.vue new file mode 100644 index 0000000..7a3256f --- /dev/null +++ b/ruoyi-ui/src/views/file/runtime/index.vue @@ -0,0 +1,170 @@ + + +