feat: 概览页增加 Swap 分区监控 (#2975)

Refs #2934  #2251
This commit is contained in:
ssongliu 2023-11-17 10:12:07 +08:00 committed by GitHub
parent 88c3559245
commit adde751b73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 214 additions and 44 deletions

View file

@ -43,7 +43,12 @@ type DashboardCurrent struct {
MemoryTotal uint64 `json:"memoryTotal"`
MemoryAvailable uint64 `json:"memoryAvailable"`
MemoryUsed uint64 `json:"memoryUsed"`
MemoryUsedPercent float64 `json:"MemoryUsedPercent"`
MemoryUsedPercent float64 `json:"memoryUsedPercent"`
SwapMemoryTotal uint64 `json:"swapMemoryTotal"`
SwapMemoryAvailable uint64 `json:"swapMemoryAvailable"`
SwapMemoryUsed uint64 `json:"swapMemoryUsed"`
SwapMemoryUsedPercent float64 `json:"swapMemoryUsedPercent"`
IOReadBytes uint64 `json:"ioReadBytes"`
IOWriteBytes uint64 `json:"ioWriteBytes"`

View file

@ -123,6 +123,12 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d
currentInfo.MemoryUsed = memoryInfo.Used
currentInfo.MemoryUsedPercent = memoryInfo.UsedPercent
swapInfo, _ := mem.SwapMemory()
currentInfo.SwapMemoryTotal = swapInfo.Total
currentInfo.SwapMemoryAvailable = swapInfo.Free
currentInfo.SwapMemoryUsed = swapInfo.Used
currentInfo.SwapMemoryUsedPercent = swapInfo.UsedPercent
currentInfo.DiskData = loadDiskInfo()
if ioOption == "all" {

View file

@ -1,5 +1,5 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
// Code generated by swaggo/swag. DO NOT EDIT.
package docs
import "github.com/swaggo/swag"
@ -13873,9 +13873,6 @@ const docTemplate = `{
"dto.DashboardCurrent": {
"type": "object",
"properties": {
"MemoryUsedPercent": {
"type": "number"
},
"cpuPercent": {
"type": "array",
"items": {
@ -13933,6 +13930,9 @@ const docTemplate = `{
"memoryUsed": {
"type": "integer"
},
"memoryUsedPercent": {
"type": "number"
},
"netBytesRecv": {
"type": "integer"
},
@ -13945,6 +13945,18 @@ const docTemplate = `{
"shotTime": {
"type": "string"
},
"swapMemoryAvailable": {
"type": "integer"
},
"swapMemoryTotal": {
"type": "integer"
},
"swapMemoryUsed": {
"type": "integer"
},
"swapMemoryUsedPercent": {
"type": "number"
},
"timeSinceUptime": {
"type": "string"
},
@ -16712,12 +16724,21 @@ const docTemplate = `{
"createdAt": {
"type": "string"
},
"eabHmacKey": {
"type": "string"
},
"eabKid": {
"type": "string"
},
"email": {
"type": "string"
},
"id": {
"type": "integer"
},
"type": {
"type": "string"
},
"updatedAt": {
"type": "string"
},
@ -17610,8 +17631,6 @@ const docTemplate = `{
"type": "object",
"required": [
"operate",
"password",
"username",
"websiteID"
],
"properties": {
@ -17660,8 +17679,7 @@ const docTemplate = `{
"request.NginxConfigUpdate": {
"type": "object",
"required": [
"operate",
"websiteId"
"operate"
],
"properties": {
"operate": {
@ -18094,11 +18112,27 @@ const docTemplate = `{
"request.WebsiteAcmeAccountCreate": {
"type": "object",
"required": [
"email"
"email",
"type"
],
"properties": {
"eabHmacKey": {
"type": "string"
},
"eabKid": {
"type": "string"
},
"email": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"letsencrypt",
"zerossl",
"buypass",
"google"
]
}
}
},
@ -18193,9 +18227,6 @@ const docTemplate = `{
},
"request.WebsiteDefaultUpdate": {
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "integer"
@ -19188,12 +19219,21 @@ const docTemplate = `{
"createdAt": {
"type": "string"
},
"eabHmacKey": {
"type": "string"
},
"eabKid": {
"type": "string"
},
"email": {
"type": "string"
},
"id": {
"type": "integer"
},
"type": {
"type": "string"
},
"updatedAt": {
"type": "string"
},

View file

@ -13866,9 +13866,6 @@
"dto.DashboardCurrent": {
"type": "object",
"properties": {
"MemoryUsedPercent": {
"type": "number"
},
"cpuPercent": {
"type": "array",
"items": {
@ -13926,6 +13923,9 @@
"memoryUsed": {
"type": "integer"
},
"memoryUsedPercent": {
"type": "number"
},
"netBytesRecv": {
"type": "integer"
},
@ -13938,6 +13938,18 @@
"shotTime": {
"type": "string"
},
"swapMemoryAvailable": {
"type": "integer"
},
"swapMemoryTotal": {
"type": "integer"
},
"swapMemoryUsed": {
"type": "integer"
},
"swapMemoryUsedPercent": {
"type": "number"
},
"timeSinceUptime": {
"type": "string"
},
@ -16705,12 +16717,21 @@
"createdAt": {
"type": "string"
},
"eabHmacKey": {
"type": "string"
},
"eabKid": {
"type": "string"
},
"email": {
"type": "string"
},
"id": {
"type": "integer"
},
"type": {
"type": "string"
},
"updatedAt": {
"type": "string"
},
@ -17603,8 +17624,6 @@
"type": "object",
"required": [
"operate",
"password",
"username",
"websiteID"
],
"properties": {
@ -17653,8 +17672,7 @@
"request.NginxConfigUpdate": {
"type": "object",
"required": [
"operate",
"websiteId"
"operate"
],
"properties": {
"operate": {
@ -18087,11 +18105,27 @@
"request.WebsiteAcmeAccountCreate": {
"type": "object",
"required": [
"email"
"email",
"type"
],
"properties": {
"eabHmacKey": {
"type": "string"
},
"eabKid": {
"type": "string"
},
"email": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"letsencrypt",
"zerossl",
"buypass",
"google"
]
}
}
},
@ -18186,9 +18220,6 @@
},
"request.WebsiteDefaultUpdate": {
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "integer"
@ -19181,12 +19212,21 @@
"createdAt": {
"type": "string"
},
"eabHmacKey": {
"type": "string"
},
"eabKid": {
"type": "string"
},
"email": {
"type": "string"
},
"id": {
"type": "integer"
},
"type": {
"type": "string"
},
"updatedAt": {
"type": "string"
},

View file

@ -736,8 +736,6 @@ definitions:
type: object
dto.DashboardCurrent:
properties:
MemoryUsedPercent:
type: number
cpuPercent:
items:
type: number
@ -776,6 +774,8 @@ definitions:
type: integer
memoryUsed:
type: integer
memoryUsedPercent:
type: number
netBytesRecv:
type: integer
netBytesSent:
@ -784,6 +784,14 @@ definitions:
type: integer
shotTime:
type: string
swapMemoryAvailable:
type: integer
swapMemoryTotal:
type: integer
swapMemoryUsed:
type: integer
swapMemoryUsedPercent:
type: number
timeSinceUptime:
type: string
uptime:
@ -2645,10 +2653,16 @@ definitions:
properties:
createdAt:
type: string
eabHmacKey:
type: string
eabKid:
type: string
email:
type: string
id:
type: integer
type:
type: string
updatedAt:
type: string
url:
@ -3255,8 +3269,6 @@ definitions:
type: integer
required:
- operate
- password
- username
- websiteID
type: object
request.NginxCommonReq:
@ -3290,7 +3302,6 @@ definitions:
type: integer
required:
- operate
- websiteId
type: object
request.NginxProxyUpdate:
properties:
@ -3569,10 +3580,22 @@ definitions:
type: object
request.WebsiteAcmeAccountCreate:
properties:
eabHmacKey:
type: string
eabKid:
type: string
email:
type: string
type:
enum:
- letsencrypt
- zerossl
- buypass
- google
type: string
required:
- email
- type
type: object
request.WebsiteCommonReq:
properties:
@ -3638,8 +3661,6 @@ definitions:
properties:
id:
type: integer
required:
- id
type: object
request.WebsiteDelete:
properties:
@ -4299,10 +4320,16 @@ definitions:
properties:
createdAt:
type: string
eabHmacKey:
type: string
eabKid:
type: string
email:
type: string
id:
type: integer
type:
type: string
updatedAt:
type: string
url:

View file

@ -38,7 +38,11 @@ export namespace Dashboard {
memoryTotal: number;
memoryAvailable: number;
memoryUsed: number;
MemoryUsedPercent: number;
memoryUsedPercent: number;
swapMemoryTotal: number;
swapMemoryAvailable: number;
swapMemoryUsed: number;
swapMemoryUsedPercent: number;
ioReadBytes: number;
ioWriteBytes: number;

View file

@ -305,6 +305,8 @@ const message = {
ioDelay: 'IO delay',
uptime: 'Up Time',
runningTime: 'Running Time',
mem: 'System',
swapMem: 'Swap Partition',
runSmoothly: 'Run smoothly',
runNormal: 'Run normal',

View file

@ -302,6 +302,8 @@ const message = {
ioDelay: '讀寫延遲',
uptime: '啟動時間',
runningTime: '運行時間',
mem: '系統',
swapMem: 'Swap 分區',
runSmoothly: '運行流暢',
runNormal: '運行正常',

View file

@ -302,6 +302,8 @@ const message = {
ioDelay: '读写延迟',
uptime: '启动时间',
runningTime: '运行时间',
mem: '系统',
swapMem: 'Swap 分区',
runSmoothly: '运行流畅',
runNormal: '运行正常',

View file

@ -319,7 +319,11 @@ const currentInfo = ref<Dashboard.CurrentInfo>({
memoryTotal: 0,
memoryAvailable: 0,
memoryUsed: 0,
MemoryUsedPercent: 0,
memoryUsedPercent: 0,
swapMemoryTotal: 0,
swapMemoryAvailable: 0,
swapMemoryUsed: 0,
swapMemoryUsedPercent: 0,
ioReadBytes: 0,
ioWriteBytes: 0,
@ -389,7 +393,7 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => {
if (isActive.value && !globalStore.isOnRestart) {
await onLoadCurrentInfo();
}
}, 3000);
}, 300000);
}
};

View file

@ -43,13 +43,47 @@
</span>
</el-col>
<el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6" align="center">
<v-charts
height="160px"
id="memory"
type="pie"
:option="chartsOption['memory']"
v-if="chartsOption['memory']"
/>
<el-popover placement="bottom" :width="160" trigger="hover">
<el-tag style="font-weight: 500">{{ $t('home.mem') }}:</el-tag>
<el-tag class="tagClass">
{{ $t('home.total') }}: {{ formatNumber(currentInfo.memoryTotal / 1024 / 1024) }} MB
</el-tag>
<el-tag class="tagClass">
{{ $t('home.used') }}: {{ formatNumber(currentInfo.memoryUsed / 1024 / 1024) }} MB
</el-tag>
<el-tag class="tagClass">
{{ $t('home.free') }}: {{ formatNumber(currentInfo.memoryAvailable / 1024 / 1024) }} MB
</el-tag>
<el-tag class="tagClass">
{{ $t('home.percent') }}: {{ formatNumber(currentInfo.memoryUsedPercent) }}%
</el-tag>
<div v-if="currentInfo.swapMemoryTotal">
<el-row :gutter="5" class="mt-2">
<el-tag style="font-weight: 500">{{ $t('home.swapMem') }}:</el-tag>
</el-row>
<el-tag class="tagClass">
{{ $t('home.total') }}: {{ formatNumber(currentInfo.swapMemoryTotal / 1024 / 1024) }} MB
</el-tag>
<el-tag class="tagClass">
{{ $t('home.used') }}: {{ formatNumber(currentInfo.swapMemoryUsed / 1024 / 1024) }} MB
</el-tag>
<el-tag class="tagClass">
{{ $t('home.free') }}: {{ formatNumber(currentInfo.swapMemoryAvailable / 1024 / 1024) }} MB
</el-tag>
<el-tag class="tagClass">
{{ $t('home.percent') }}: {{ formatNumber(100 - currentInfo.swapMemoryUsedPercent * 100) }}%
</el-tag>
</div>
<template #reference>
<v-charts
height="160px"
id="memory"
type="pie"
:option="chartsOption['memory']"
v-if="chartsOption['memory']"
/>
</template>
</el-popover>
<span class="input-help">
( {{ formatNumber(currentInfo.memoryUsed / 1024 / 1024) }} /
{{ formatNumber(currentInfo.memoryTotal / 1024 / 1024) }} ) MB
@ -193,7 +227,11 @@ const currentInfo = ref<Dashboard.CurrentInfo>({
memoryTotal: 0,
memoryAvailable: 0,
memoryUsed: 0,
MemoryUsedPercent: 0,
memoryUsedPercent: 0,
swapMemoryTotal: 0,
swapMemoryAvailable: 0,
swapMemoryUsed: 0,
swapMemoryUsedPercent: 0,
ioReadBytes: 0,
ioWriteBytes: 0,
@ -219,7 +257,7 @@ const acceptParams = (current: Dashboard.CurrentInfo, base: Dashboard.BaseInfo,
};
chartsOption.value['memory'] = {
title: i18n.global.t('monitor.memory'),
data: formatNumber(currentInfo.value.MemoryUsedPercent),
data: formatNumber(currentInfo.value.memoryUsedPercent),
};
chartsOption.value['load'] = {
title: i18n.global.t('home.load'),