mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-22 01:00:24 +08:00
[API节点]列表显示版本号、CPU、内存、状态等信息
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -36,11 +41,32 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range nodesResp.Nodes {
|
for _, node := range nodesResp.Nodes {
|
||||||
|
// 状态
|
||||||
|
status := &nodeconfigs.NodeStatus{}
|
||||||
|
if len(node.StatusJSON) > 0 {
|
||||||
|
err = json.Unmarshal(node.StatusJSON, &status)
|
||||||
|
if err != nil {
|
||||||
|
logs.Error(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
status.IsActive = status.IsActive && time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
|
||||||
|
}
|
||||||
|
|
||||||
nodeMaps = append(nodeMaps, maps.Map{
|
nodeMaps = append(nodeMaps, maps.Map{
|
||||||
"id": node.Id,
|
"id": node.Id,
|
||||||
"isOn": node.IsOn,
|
"isOn": node.IsOn,
|
||||||
"name": node.Name,
|
"name": node.Name,
|
||||||
"accessAddrs": node.AccessAddrs,
|
"accessAddrs": node.AccessAddrs,
|
||||||
|
"status": maps.Map{
|
||||||
|
"isActive": status.IsActive,
|
||||||
|
"updatedAt": status.UpdatedAt,
|
||||||
|
"hostname": status.Hostname,
|
||||||
|
"cpuUsage": status.CPUUsage,
|
||||||
|
"cpuUsageText": fmt.Sprintf("%.2f%%", status.CPUUsage*100),
|
||||||
|
"memUsage": status.MemoryUsage,
|
||||||
|
"memUsageText": fmt.Sprintf("%.2f%%", status.MemoryUsage*100),
|
||||||
|
"buildVersion": status.BuildVersion,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,13 @@ table th.width10 {
|
|||||||
table th.width5 {
|
table th.width5 {
|
||||||
width: 5em;
|
width: 5em;
|
||||||
}
|
}
|
||||||
|
table th.width6 {
|
||||||
|
width: 6em;
|
||||||
|
}
|
||||||
textarea::-webkit-scrollbar {
|
textarea::-webkit-scrollbar {
|
||||||
width: 6px !important;
|
width: 6px !important;
|
||||||
}
|
}
|
||||||
select.dropdown {
|
select.dropdown {
|
||||||
height: auto!important;
|
height: auto !important;
|
||||||
}
|
}
|
||||||
/*# sourceMappingURL=@layout_override.css.map */
|
/*# sourceMappingURL=@layout_override.css.map */
|
||||||
@@ -1 +1 @@
|
|||||||
{"version":3,"sources":["@layout_override.less"],"names":[],"mappings":"AACA,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,QAAO;EACrG,oCAAA;;AAGD,GAAG,OAAO,SAAU,MAAK,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,QAAS,QAAO;EACzF,oCAAA;;AAGD,GAAG,MAAM;EACR,kCAAA;;AAID,IACC;EACC,2BAAA;;AAKF,KAAK;EACJ,sBAAA;;AAGD,KAAK,KAAK;EACT,yBAAA;;AAID,KACC,GAAE;AADH,KACY,GAAE;EACZ,6BAAA;;AAFF,KAKC,GAAE;EACD,WAAA;;AANF,KASC,GAAE;EACD,UAAA;;AAKF,QAAQ;EACP,qBAAA;;AAID,MAAM;EACL,sBAAA","file":"@layout_override.css"}
|
{"version":3,"sources":["@layout_override.less"],"names":[],"mappings":"AACA,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,QAAO;EACrG,oCAAA;;AAGD,GAAG,OAAO,SAAU,MAAK,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,QAAS,QAAO;EACzF,oCAAA;;AAGD,GAAG,MAAM;EACR,kCAAA;;AAID,IACC;EACC,2BAAA;;AAKF,KAAK;EACJ,sBAAA;;AAGD,KAAK,KAAK;EACT,yBAAA;;AAID,KACC,GAAE;AADH,KACY,GAAE;EACZ,6BAAA;;AAFF,KAKC,GAAE;EACD,WAAA;;AANF,KASC,GAAE;EACD,UAAA;;AAVF,KAaC,GAAE;EACD,UAAA;;AAKF,QAAQ;EACP,qBAAA;;AAID,MAAM;EACL,uBAAA","file":"@layout_override.css"}
|
||||||
@@ -40,6 +40,10 @@ table {
|
|||||||
th.width5 {
|
th.width5 {
|
||||||
width: 5em;
|
width: 5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
th.width6 {
|
||||||
|
width: 6em;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// textarea
|
// textarea
|
||||||
@@ -49,5 +53,5 @@ textarea::-webkit-scrollbar {
|
|||||||
|
|
||||||
// dropdown
|
// dropdown
|
||||||
select.dropdown {
|
select.dropdown {
|
||||||
height: auto!important;
|
height: auto !important;
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>节点名称</th>
|
<th>节点名称</th>
|
||||||
<th>访问地址</th>
|
<th>访问地址</th>
|
||||||
|
<th class="width6 center">版本号</th>
|
||||||
|
<th class="width5 center">CPU</th>
|
||||||
|
<th class="width5 center">内存</th>
|
||||||
<th class="center width10">状态</th>
|
<th class="center width10">状态</th>
|
||||||
<th class="two op">操作</th>
|
<th class="two op">操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -23,7 +26,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="center">
|
<td class="center">
|
||||||
<label-on :v-is-on="node.isOn"></label-on>
|
<span v-if="node.status.buildVersion.length > 0">v{{node.status.buildVersion}}</span>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
<td class="center">
|
||||||
|
<span v-if="node.status.isActive" :class="{red:node.status.cpuUsage > 0.80}">{{node.status.cpuUsageText}}</span>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
<td class="center">
|
||||||
|
<span v-if="node.status.isActive" :class="{red:node.status.memUsage > 0.80}">{{node.status.memUsageText}}</span>
|
||||||
|
<span v-else class="disabled">-</span>
|
||||||
|
</td>
|
||||||
|
<td class="center">
|
||||||
|
<span v-if="!node.isOn"><label-on :v-is-on="node.isOn"></label-on></span>
|
||||||
|
<div v-else-if="node.status.isActive">
|
||||||
|
<span class="green">运行中</span>
|
||||||
|
</div>
|
||||||
|
<span v-else-if="node.status.updatedAt > 0" class="red">已断开</span>
|
||||||
|
<span v-else-if="node.status.updatedAt == 0" class="red">未连接</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a :href="'/api/node?nodeId=' + node.id">详情</a>
|
<a :href="'/api/node?nodeId=' + node.id">详情</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user