From adde751b73d7ff8e851ffb1fb10be533cfe03b3b Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Fri, 17 Nov 2023 10:12:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A6=82=E8=A7=88=E9=A1=B5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20Swap=20=E5=88=86=E5=8C=BA=E7=9B=91=E6=8E=A7=20(#297?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #2934 #2251 --- backend/app/dto/dashboard.go | 7 ++- backend/app/service/dashboard.go | 6 +++ cmd/server/docs/docs.go | 66 +++++++++++++++++++----- cmd/server/docs/swagger.json | 62 ++++++++++++++++++---- cmd/server/docs/swagger.yaml | 41 ++++++++++++--- frontend/src/api/interface/dashboard.ts | 6 ++- frontend/src/lang/modules/en.ts | 2 + frontend/src/lang/modules/tw.ts | 2 + frontend/src/lang/modules/zh.ts | 2 + frontend/src/views/home/index.vue | 8 ++- frontend/src/views/home/status/index.vue | 56 ++++++++++++++++---- 11 files changed, 214 insertions(+), 44 deletions(-) diff --git a/backend/app/dto/dashboard.go b/backend/app/dto/dashboard.go index ee37a5677..1d2f46efe 100644 --- a/backend/app/dto/dashboard.go +++ b/backend/app/dto/dashboard.go @@ -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"` diff --git a/backend/app/service/dashboard.go b/backend/app/service/dashboard.go index 0a37ecfda..68adf8831 100644 --- a/backend/app/service/dashboard.go +++ b/backend/app/service/dashboard.go @@ -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" { diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 9205829b2..4ef8a06df 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -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" }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 95b7eb021..4228d152e 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -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" }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 6aa39f996..4171f3ddd 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -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: diff --git a/frontend/src/api/interface/dashboard.ts b/frontend/src/api/interface/dashboard.ts index ca50312c0..77ef5515a 100644 --- a/frontend/src/api/interface/dashboard.ts +++ b/frontend/src/api/interface/dashboard.ts @@ -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; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index dbc534f86..9e996ba20 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -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', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index d9474ffc8..fa3432c52 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -302,6 +302,8 @@ const message = { ioDelay: '讀寫延遲', uptime: '啟動時間', runningTime: '運行時間', + mem: '系統', + swapMem: 'Swap 分區', runSmoothly: '運行流暢', runNormal: '運行正常', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 98971c757..49b892137 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -302,6 +302,8 @@ const message = { ioDelay: '读写延迟', uptime: '启动时间', runningTime: '运行时间', + mem: '系统', + swapMem: 'Swap 分区', runSmoothly: '运行流畅', runNormal: '运行正常', diff --git a/frontend/src/views/home/index.vue b/frontend/src/views/home/index.vue index f0a108b8e..62ae1b246 100644 --- a/frontend/src/views/home/index.vue +++ b/frontend/src/views/home/index.vue @@ -319,7 +319,11 @@ const currentInfo = ref({ 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); } }; diff --git a/frontend/src/views/home/status/index.vue b/frontend/src/views/home/status/index.vue index 68162352f..5f60f90aa 100644 --- a/frontend/src/views/home/status/index.vue +++ b/frontend/src/views/home/status/index.vue @@ -43,13 +43,47 @@ - + + {{ $t('home.mem') }}: + + {{ $t('home.total') }}: {{ formatNumber(currentInfo.memoryTotal / 1024 / 1024) }} MB + + + {{ $t('home.used') }}: {{ formatNumber(currentInfo.memoryUsed / 1024 / 1024) }} MB + + + {{ $t('home.free') }}: {{ formatNumber(currentInfo.memoryAvailable / 1024 / 1024) }} MB + + + {{ $t('home.percent') }}: {{ formatNumber(currentInfo.memoryUsedPercent) }}% + +
+ + {{ $t('home.swapMem') }}: + + + {{ $t('home.total') }}: {{ formatNumber(currentInfo.swapMemoryTotal / 1024 / 1024) }} MB + + + {{ $t('home.used') }}: {{ formatNumber(currentInfo.swapMemoryUsed / 1024 / 1024) }} MB + + + {{ $t('home.free') }}: {{ formatNumber(currentInfo.swapMemoryAvailable / 1024 / 1024) }} MB + + + {{ $t('home.percent') }}: {{ formatNumber(100 - currentInfo.swapMemoryUsedPercent * 100) }}% + +
+ +
( {{ formatNumber(currentInfo.memoryUsed / 1024 / 1024) }} / {{ formatNumber(currentInfo.memoryTotal / 1024 / 1024) }} ) MB @@ -193,7 +227,11 @@ const currentInfo = ref({ 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'),