Explorar o código

添加 JVM 信息和状态页面接口和前端页面

reghao %!s(int64=4) %!d(string=hai) anos
pai
achega
a9dba52840

+ 4 - 4
common/src/main/java/cn/reghao/autodop/common/jvm/JVM.java

@@ -31,8 +31,8 @@ public class JVM {
         this.gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
     }
 
-    public JVMInfo info() {
-        JVMInfo jvmInfo = new JVMInfo();
+    public JvmInfo info() {
+        JvmInfo jvmInfo = new JvmInfo();
         jvmInfo.setOsName(System.getProperty("os.name"));
         jvmInfo.setOsArch(System.getProperty("os.arch"));
         jvmInfo.setOsVersion(System.getProperty("os.version"));
@@ -52,8 +52,8 @@ public class JVM {
         return jvmInfo;
     }
 
-    public JVMStat stat() {
-        JVMStat jvmStat = new JVMStat();
+    public JvmStat stat() {
+        JvmStat jvmStat = new JvmStat();
         jvmStat.setJvmClassesLoaded(classLoadingBean.getLoadedClassCount());
         jvmStat.setJvmClassesUnloaded(classLoadingBean.getUnloadedClassCount());
         jvmStat.setJvmClassesTotal(classLoadingBean.getTotalLoadedClassCount());

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/jvm/pojo/JVMInfo.java → common/src/main/java/cn/reghao/autodop/common/jvm/pojo/JvmInfo.java

@@ -7,7 +7,7 @@ import lombok.Data;
  * @date 2020-10-21 10:43:37
  */
 @Data
-public class JVMInfo {
+public class JvmInfo {
     private String osName;
     private String osArch;
     private String osVersion;

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/jvm/pojo/JVMStat.java → common/src/main/java/cn/reghao/autodop/common/jvm/pojo/JvmStat.java

@@ -10,7 +10,7 @@ import java.util.Map;
  * @date 2020-10-22 15:06:29
  */
 @Data
-public class JVMStat {
+public class JvmStat {
     /* 类加载情况 */
     private long jvmClassesLoaded;
     private long jvmClassesUnloaded;

+ 1 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/db/crud/config/AppCrudService.java

@@ -50,6 +50,7 @@ public class AppCrudService {
         this.runningRepository = runningRepository;
     }
 
+    // TODO 数据修改后要在引用它的对象中立即体现
     //@CachePut(cacheNames = {"app"}, key = "#app.appId")
     @Transactional(rollbackFor = Exception.class)
     public Result insertOrUpdate(AppOrchestration app) throws Exception {

+ 0 - 41
dmaster/src/main/java/cn/reghao/autodop/dmaster/monitor/controller/JvmMonitorController.java

@@ -1,41 +0,0 @@
-package cn.reghao.autodop.dmaster.monitor.controller;
-
-import cn.reghao.autodop.dmaster.monitor.service.JvmMonitorService;
-import cn.reghao.autodop.dmaster.utils.WebBody;
-import io.swagger.annotations.Api;
-import org.springframework.web.bind.annotation.*;
-
-/**
- * @author reghao
- * @date 2019-11-15 08:44:50
- */
-@Api(tags = "JVM 监控接口")
-@RestController
-@RequestMapping("/api/monitor")
-public class JvmMonitorController {
-    private JvmMonitorService jvmMonitorService;
-
-    public JvmMonitorController(JvmMonitorService jvmMonitorService) {
-        this.jvmMonitorService = jvmMonitorService;
-    }
-
-    @GetMapping("/jvm/info")
-    public String jvmInfo() {
-        return WebBody.success(jvmMonitorService.jvmInfo());
-    }
-
-    @GetMapping("/jvm/stat")
-    public String jvmStat() {
-        return WebBody.success(jvmMonitorService.jvmStat());
-    }
-
-    @GetMapping("/linux/info")
-    public String osInfo() {
-        return WebBody.success(jvmMonitorService.jvmInfo());
-    }
-
-    @GetMapping("/linux/stat")
-    public String osStat() {
-        return WebBody.success();
-    }
-}

+ 43 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/monitor/controller/JvmPageController.java

@@ -0,0 +1,43 @@
+package cn.reghao.autodop.dmaster.monitor.controller;
+
+import cn.reghao.autodop.common.jvm.pojo.JvmInfo;
+import cn.reghao.autodop.common.jvm.pojo.JvmStat;
+import cn.reghao.autodop.dmaster.monitor.service.JvmMonitorService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author reghao
+ * @date 2019-11-15 08:44:50
+ */
+@Slf4j
+@Api(tags = "JVM 监控页面")
+@Controller
+@RequestMapping("/monitor/jvm")
+public class JvmPageController {
+    private JvmMonitorService jvmMonitorService;
+
+    public JvmPageController(JvmMonitorService jvmMonitorService) {
+        this.jvmMonitorService = jvmMonitorService;
+    }
+
+    @ApiOperation(value = "JVM 信息页面")
+    @GetMapping("/info")
+    public String jvmInfo(Model model) {
+        JvmInfo jvmInfo = jvmMonitorService.jvmInfo();
+        model.addAttribute("jvmInfo", jvmInfo);
+        return "/monitor/jvminfo";
+    }
+
+    @ApiOperation(value = "JVM 状态页面")
+    @GetMapping("/stat")
+    public String jvmStat(Model model) {
+        JvmStat jvmStat = jvmMonitorService.jvmStat();
+        model.addAttribute("jvmStat", jvmStat);
+        return "/monitor/jvmstat";
+    }
+}

+ 4 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/monitor/service/JvmMonitorService.java

@@ -1,8 +1,8 @@
 package cn.reghao.autodop.dmaster.monitor.service;
 
 import cn.reghao.autodop.common.jvm.JVM;
-import cn.reghao.autodop.common.jvm.pojo.JVMInfo;
-import cn.reghao.autodop.common.jvm.pojo.JVMStat;
+import cn.reghao.autodop.common.jvm.pojo.JvmInfo;
+import cn.reghao.autodop.common.jvm.pojo.JvmStat;
 import org.springframework.stereotype.Service;
 
 /**
@@ -17,11 +17,11 @@ public class JvmMonitorService {
         this.jvm = new JVM();
     }
 
-    public JVMInfo jvmInfo() {
+    public JvmInfo jvmInfo() {
         return jvm.info();
     }
 
-    public JVMStat jvmStat() {
+    public JvmStat jvmStat() {
         return jvm.stat();
     }
 }

+ 53 - 0
dmaster/src/main/resources/templates/monitor/jvminfo.html

@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>
+
+<body>
+    <div class="timo-detail-page">
+        <div class="timo-detail-title">系统信息</div>
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>系统名字</th>
+                <td th:text="${jvmInfo.osName}"></td>
+                <th>系统架构</th>
+                <td th:text="${jvmInfo.osArch}"></td>
+                <th>系统版本</th>
+                <td th:text="${jvmInfo.osVersion}"></td>
+            </tr>
+            </tbody>
+        </table>
+        <div class="timo-detail-title">Java 信息</div>
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>Java Runtime 名字</th>
+                <td th:text="${jvmInfo.javaRuntimeName}"></td>
+                <th>Java Runtime 版本</th>
+                <td th:text="${jvmInfo.javaRuntimeVersion}"></td>
+                <th>Java Class 版本</th>
+                <td th:text="${jvmInfo.javaClassVersion}"></td>
+            </tr>
+            </tbody>
+        </table>
+        <div class="timo-detail-title">JVM 信息</div>
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>JVM 名字</th>
+                <td th:text="${jvmInfo.jvmName}"></td>
+                <th>JVM 版本</th>
+                <td th:text="${jvmInfo.jvmVersion}"></td>
+                <th>JVM Vendor</th>
+                <td th:text="${jvmInfo.jvmVendor}"></td>
+                <th>JVM 进程 ID</th>
+                <td th:text="${jvmInfo.jvmPid}"></td>
+                <th>JVM 启动时间</th>
+                <td th:text="${jvmInfo.jvmStartTime}"></td>
+            </tr>
+            </tbody>
+        </table>
+    </div>
+    <script th:replace="/common/template :: script"></script>
+</body>
+</html>

+ 51 - 0
dmaster/src/main/resources/templates/monitor/jvmstat.html

@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>
+
+<body>
+    <div class="timo-detail-page">
+        <div class="timo-detail-title">类加载详情</div>
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>已加载类数量</th>
+                <td th:text="${jvmStat.jvmClassesLoaded}"></td>
+                <th>未加载类数量</th>
+                <td th:text="${jvmStat.jvmClassesUnloaded}"></td>
+                <th>JVM 总的类总量</th>
+                <td th:text="${jvmStat.jvmClassesTotal}"></td>
+            </tr>
+            </tbody>
+        </table>
+        <div class="timo-detail-title">堆区和非堆区内存详情</div>
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>初始化堆大小</th>
+                <td th:text="${jvmStat.jvmMemoryHeapInit}"></td>
+                <th>堆最大值</th>
+                <td th:text="${jvmStat.jvmMemoryHeapMax}"></td>
+                <th>已使用堆大小</th>
+                <td th:text="${jvmStat.jvmMemoryHeapUsed}"></td>
+                <th>已提交堆大小</th>
+                <td th:text="${jvmStat.jvmMemoryHeapCommitted}"></td>
+            </tr>
+            </tbody>
+        </table>
+        <div class="timo-detail-title">线程详情</div>
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>活动线程数</th>
+                <td th:text="${jvmStat.jvmThreadsLive}"></td>
+                <th>守护线程数</th>
+                <td th:text="${jvmStat.jvmThreadsDaemon}"></td>
+                <th>线程最大数</th>
+                <td th:text="${jvmStat.jvmThreadsPeak}"></td>
+            </tr>
+            </tbody>
+        </table>
+    </div>
+    <script th:replace="/common/template :: script"></script>
+</body>
+</html>

+ 15 - 0
dmaster/src/test/java/cn/reghao/autodop/common/jvm/JVMTest.java

@@ -0,0 +1,15 @@
+package cn.reghao.autodop.common.jvm;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class JVMTest {
+    @Test
+    void info() {
+    }
+
+    @Test
+    void stat() {
+    }
+}