Selaa lähdekoodia

调整机器列表和机器状态页面和接口

reghao 4 vuotta sitten
vanhempi
commit
7642534e73

+ 1 - 0
common/src/main/java/cn/reghao/autodop/common/dagent/machine/network/TcpConnStat.java

@@ -16,6 +16,7 @@ public class TcpConnStat {
     private String remoteAddr;
     private int remotePort;
     private String tcpState;
+    // TODO 数据单位
     private long sendq;
     private long recvq;
     private int pid;

+ 32 - 16
dmaster/src/main/java/cn/reghao/autodop/dmaster/machine/controller/MachinePageController.java

@@ -1,11 +1,13 @@
 package cn.reghao.autodop.dmaster.machine.controller;
 
+import cn.reghao.autodop.common.utils.DateTimeConverter;
 import cn.reghao.autodop.dmaster.app.constant.EnvType;
 import cn.reghao.autodop.dmaster.app.vo.KeyValue;
 import cn.reghao.autodop.dmaster.machine.db.crud.MachineHostCrudService;
 import cn.reghao.autodop.dmaster.machine.db.crud.MachineInfoCrudService;
 import cn.reghao.autodop.dmaster.machine.db.crud.MachineStatCrudService;
 import cn.reghao.autodop.dmaster.machine.db.query.MachineHostQuery;
+import cn.reghao.autodop.dmaster.machine.db.query.MachineStatQuery;
 import cn.reghao.autodop.dmaster.machine.entity.SshConnData;
 import cn.reghao.autodop.dmaster.machine.entity.po.MachineHost;
 import cn.reghao.autodop.dmaster.machine.entity.po.MachineStat;
@@ -29,6 +31,7 @@ import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -46,17 +49,20 @@ public class MachinePageController {
     private MachineInfoCrudService infoCrudService;
     private MachineHostCrudService hostCrudService;
     private MachineHostQuery hostQuery;
+    private MachineStatQuery statQuery;
     private MachineStatCrudService statCrudService;
     private NotifyGroupRepository receiverRepository;
 
     public MachinePageController(MachineInfoCrudService infoCrudService,
                                  MachineHostCrudService hostCrudService,
                                  MachineHostQuery hostQuery,
+                                 MachineStatQuery statQuery,
                                  MachineStatCrudService statCrudService,
                                  NotifyGroupRepository receiverRepository) {
         this.infoCrudService = infoCrudService;
         this.hostCrudService = hostCrudService;
         this.hostQuery = hostQuery;
+        this.statQuery = statQuery;
         this.statCrudService = statCrudService;
         this.receiverRepository = receiverRepository;
     }
@@ -164,46 +170,56 @@ public class MachinePageController {
     @ApiOperation(value = "机器系统负载页面")
     @GetMapping("/status/sys/{machineId}")
     public String hostStatusPage(@PathVariable("machineId") String machineId, Model model) {
+        MachineStat machineStat = statQuery.query(machineId);
+        LocalDateTime statTime = machineStat.getMachineTime();
+
+        model.addAttribute("statTime", DateTimeConverter.format(statTime));
+        model.addAttribute("sysload", machineStat.getOsStat());
         return "/machine/sysload";
     }
 
     @ApiOperation(value = "网络状态页面")
     @GetMapping("/status/network/{machineId}")
     public String networkStatusPage(@PathVariable("machineId") String machineId, Model model) {
-        MachineStat machineStat = statCrudService.selectByUk(machineId);
-        if (machineStat != null) {
-            model.addAttribute("memoryUsage", machineStat.getMemoryUsage());
-        }
+        MachineStat machineStat = statQuery.query(machineId);
+        LocalDateTime statTime = machineStat.getMachineTime();
+
+        model.addAttribute("statTime", DateTimeConverter.format(statTime));
+        model.addAttribute("tcpConnNum", machineStat.getTcpConnNum());
+        model.addAttribute("networkStat", machineStat.getNetworkStat());
         return "/machine/networkstatus";
     }
 
     @ApiOperation(value = "CPU 使用率页面")
     @GetMapping("/status/cpu/{machineId}")
     public String cpuUsagePage(@PathVariable("machineId") String machineId, Model model) {
-        MachineStat machineStat = statCrudService.selectByUk(machineId);
-        if (machineStat != null) {
-            model.addAttribute("memoryUsage", machineStat.getMemoryUsage());
-        }
+        MachineStat machineStat = statQuery.query(machineId);
+        LocalDateTime statTime = machineStat.getMachineTime();
+
+        model.addAttribute("statTime", DateTimeConverter.format(statTime));
+        model.addAttribute("cpuUsage", machineStat.getCpuStat());
         return "/machine/cpuusage";
     }
 
     @ApiOperation(value = "内存详情页面")
     @GetMapping("/status/mem/{machineId}")
     public String memUsagePage(@PathVariable("machineId") String machineId, Model model) {
-        MachineStat machineStat = statCrudService.selectByUk(machineId);
-        if (machineStat != null) {
-            model.addAttribute("memoryUsage", machineStat.getMemoryUsage());
-        }
+        MachineStat machineStat = statQuery.query(machineId);
+        LocalDateTime statTime = machineStat.getMachineTime();
+
+        model.addAttribute("statTime", DateTimeConverter.format(statTime));
+        model.addAttribute("memoryUsage", machineStat.getMemoryUsage());
         return "/machine/memusage";
     }
 
     @ApiOperation(value = "磁盘详情页面")
     @GetMapping("/status/disk/{machineId}")
     public String diskUsagePage(@PathVariable("machineId") String machineId, Model model) {
-        MachineStat machineStat = statCrudService.selectByUk(machineId);
-        if (machineStat != null) {
-            model.addAttribute("diskUsages", machineStat.getDiskUsages());
-        }
+        MachineStat machineStat = statQuery.query(machineId);
+        LocalDateTime statTime = machineStat.getMachineTime();
+
+        model.addAttribute("statTime", DateTimeConverter.format(statTime));
+        model.addAttribute("diskUsages", machineStat.getDiskUsages());
         return "/machine/diskusage";
     }
 }

+ 34 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/machine/db/query/MachineStatQuery.java

@@ -0,0 +1,34 @@
+package cn.reghao.autodop.dmaster.machine.db.query;
+
+import cn.reghao.autodop.dmaster.machine.entity.po.MachineStat;
+import org.bson.Document;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author reghao
+ * @date 2021-06-17 22:52:32
+ */
+@Service
+public class MachineStatQuery {
+    private MongoTemplate mongoTemplate;
+
+    public MachineStatQuery(MongoTemplate mongoTemplate) {
+        this.mongoTemplate = mongoTemplate;
+    }
+
+    public MachineStat query(String machineId) {
+        Query query = new Query();
+        query.addCriteria(Criteria.where("machineId").is(machineId));
+        query.with(Sort.by(Sort.Order.desc("createTime"))).limit(1);
+        List<MachineStat> list = mongoTemplate.find(query, MachineStat.class);
+        return list.isEmpty() ? null : list.get(0);
+    }
+}

+ 9 - 1
dmaster/src/main/resources/templates/machine/cpuusage.html

@@ -4,7 +4,15 @@
 
 <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="${statTime}"></td>
+            </tr>
+            </tbody>
+        </table>
+        <div class="timo-detail-title">CPU 使用率</div>
         <table class="layui-table timo-detail-table">
             <tbody>
             <tr>

+ 8 - 0
dmaster/src/main/resources/templates/machine/diskusage.html

@@ -4,6 +4,14 @@
 
 <body>
     <div class="timo-detail-page">
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>状态时间</th>
+                <td th:text="${statTime}"></td>
+            </tr>
+            </tbody>
+        </table>
         <div class="timo-detail-title">磁盘使用情况</div>
         <table class="layui-table timo-detail-table">
             <tbody>

+ 8 - 0
dmaster/src/main/resources/templates/machine/memusage.html

@@ -4,6 +4,14 @@
 
 <body>
     <div class="timo-detail-page">
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>状态时间</th>
+                <td th:text="${statTime}"></td>
+            </tr>
+            </tbody>
+        </table>
         <div class="timo-detail-title">内存使用情况</div>
         <table class="layui-table timo-detail-table">
             <tbody>

+ 54 - 23
dmaster/src/main/resources/templates/machine/networkstatus.html

@@ -3,29 +3,60 @@
 <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:each="item:${diskUsages}">
-                <th>分区挂载路径</th>
-                <td th:text="${item.mountedOn}"></td>
-                <th>文件系统</th>
-                <td th:text="${item.fsType}"></td>
-                <th>总容量</th>
-                <td th:text="${item.total}"></td>
-                <th>已使用</th>
-                <td th:text="${item.used}"></td>
-                <th>可用</th>
-                <td th:text="${item.avail}"></td>
-                <th>inode 总量</th>
-                <td th:text="${item.inodeTotal}"></td>
-                <th>inode 可用量</th>
-                <td th:text="${item.inodeFree}"></td>
-            </tr>
-            </tbody>
-        </table>
-    </div>
+<div class="timo-detail-page">
+    <table class="layui-table timo-detail-table">
+        <tbody>
+        <tr>
+            <th>状态时间</th>
+            <td th:text="${statTime}"></td>
+        </tr>
+        <tr>
+            <th>TCP 连接数量</th>
+            <td th:text="${tcpConnNum}"></td>
+        </tr>
+        </tbody>
+    </table>
+    <div class="timo-detail-title">网络信息</div>
+    <table class="layui-table timo-detail-table">
+        <tbody>
+        <tr th:each="item:${networkStat.networkInfos}">
+            <th>网卡接口</th>
+            <td th:text="${item.iface}"></td>
+            <th>MAC 地址</th>
+            <td th:text="${item.mac}"></td>
+            <th>IPv4 地址</th>
+            <td th:text="${item.ipv4}"></td>
+            <th>IPv6 地址</th>
+            <td th:text="${item.ipv6}"></td>
+        </tr>
+        </tbody>
+    </table>
+    <div class="timo-detail-title">TCP 连接状态</div>
+    <table class="layui-table timo-detail-table">
+        <tbody>
+        <tr th:each="item:${networkStat.tcpConnStats}">
+            <th>本地地址</th>
+            <td th:text="${item.localAddr}"></td>
+            <th>本地端口</th>
+            <td th:text="${item.localPort}"></td>
+            <th>远程地址</th>
+            <td th:text="${item.remoteAddr}"></td>
+            <th>远程端口</th>
+            <td th:text="${item.remotePort}"></td>
+            <th>TCP 状态</th>
+            <td th:text="${item.tcpState}"></td>
+            <th>发送队列</th>
+            <td th:text="${item.sendq}"></td>
+            <th>接收队列</th>
+            <td th:text="${item.recvq}"></td>
+            <th>进程 ID</th>
+            <td th:text="${item.pid}"></td>
+            <th>进程名字</th>
+            <td th:text="${item.process}"></td>
+        </tr>
+        </tbody>
+    </table>
+</div>
 <script th:replace="/common/template :: script"></script>
 </body>
 </html>

+ 2 - 2
dmaster/src/main/resources/templates/machine/status.html

@@ -57,7 +57,7 @@
                     </td>
                     <td>
                         <a class="open-popup" data-title="网络状态"
-                           th:attr="data-url=@{'/machine/status/network/'+${item.machineId}}" data-size="800,600"
+                           th:attr="data-url=@{'/machine/status/network/'+${item.machineId}}" data-size="1200,600"
                            href="#">查看</a>
                     </td>
                     <td>
@@ -72,7 +72,7 @@
                     </td>
                     <td>
                         <a class="open-popup" data-title="磁盘详情"
-                           th:attr="data-url=@{'/machine/status/disk/'+${item.machineId}}" data-size="800,600"
+                           th:attr="data-url=@{'/machine/status/disk/'+${item.machineId}}" data-size="1200,600"
                            href="#">查看</a>
                     </td>
                 </tr>

+ 20 - 13
dmaster/src/main/resources/templates/machine/sysload.html

@@ -4,24 +4,31 @@
 
 <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="${memoryUsage?.total}"></td>
-                <th>已用内存</th>
-                <td th:text="${memoryUsage?.used}"></td>
-                <th>可用内存</th>
-                <td th:text="${memoryUsage?.avail}"></td>
+                <th>状态时间</th>
+                <td th:text="${statTime}"></td>
+            </tr>
+            </tbody>
+        </table>
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>过去 1 分钟</th>
+                <td th:text="${sysload.loadAvg1}"></td>
+                <th>过去 5 分钟</th>
+                <td th:text="${sysload.loadAvg5}"></td>
+                <th>过去 15 分钟</th>
+                <td th:text="${sysload.loadAvg15}"></td>
             </tr>
             <tr>
-                <th>交换分区总量</th>
-                <td th:text="${memoryUsage?.swapTotal}"></td>
-                <th>已使用交换分区</th>
-                <td th:text="${memoryUsage?.swapUsed}"></td>
-                <th>可用交换分区</th>
-                <td th:text="${memoryUsage?.swapAvail}"></td>
+                <th>当前进程数量</th>
+                <td th:text="${sysload.current}"></td>
+                <th>系统中总的进程数量</th>
+                <td th:text="${sysload.total}"></td>
+                <th>上一次运行的进程</th>
+                <td th:text="${sysload.lastPid}"></td>
             </tr>
             </tbody>
         </table>