From baf64a927280fdb04579d5afeff1b5d50e56556a Mon Sep 17 00:00:00 2001 From: Sun <95302870@qq.com> Date: Thu, 4 Jan 2024 12:08:39 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=90=84=E9=A1=B9=E7=9B=91=E6=8E=A7=E7=9A=84=E5=8D=95=E7=8B=AC?= =?UTF-8?q?api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiData/systemApiStructs/monitor.go | 5 ++ service/api/api_v1/system/monitor.go | 69 +++++++++++++++++++ service/global/global.go | 2 +- service/global/monitor.go | 10 ++- service/initialize/A_ENTER.go | 4 +- service/lib/monitor/monitor.go | 14 ++++ service/router/system/monitor.go | 3 + 7 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 service/api/api_v1/common/apiData/systemApiStructs/monitor.go diff --git a/service/api/api_v1/common/apiData/systemApiStructs/monitor.go b/service/api/api_v1/common/apiData/systemApiStructs/monitor.go new file mode 100644 index 0000000..f39f325 --- /dev/null +++ b/service/api/api_v1/common/apiData/systemApiStructs/monitor.go @@ -0,0 +1,5 @@ +package systemApiStructs + +type MonitorGetDiskStateByPathReq struct { + Path string `json:"path"` +} diff --git a/service/api/api_v1/system/monitor.go b/service/api/api_v1/system/monitor.go index e47308f..f830ae8 100644 --- a/service/api/api_v1/system/monitor.go +++ b/service/api/api_v1/system/monitor.go @@ -1,14 +1,21 @@ package system import ( + "sun-panel/api/api_v1/common/apiData/systemApiStructs" "sun-panel/api/api_v1/common/apiReturn" "sun-panel/global" + "sun-panel/lib/monitor" + "time" "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/binding" ) type MonitorApi struct{} +const cacheSecond = 3 + +// 弃用 func (a *MonitorApi) GetAll(c *gin.Context) { if value, ok := global.SystemMonitor.Get("value"); ok { apiReturn.SuccessData(c, value) @@ -16,3 +23,65 @@ func (a *MonitorApi) GetAll(c *gin.Context) { } apiReturn.Error(c, "failed") } + +func (a *MonitorApi) GetCpuState(c *gin.Context) { + if v, ok := global.SystemMonitor.Get(global.SystemMonitor_CPU_INFO); ok { + global.Logger.Debugln("读取缓存的的CPU信息") + apiReturn.SuccessData(c, v) + return + } + cpuInfo, err := monitor.GetCPUInfo() + + if err != nil { + apiReturn.Error(c, "failed") + return + } + // 缓存 + global.SystemMonitor.Set(global.SystemMonitor_CPU_INFO, cpuInfo, cacheSecond*time.Second) + apiReturn.SuccessData(c, cpuInfo) +} + +func (a *MonitorApi) GetMemonyState(c *gin.Context) { + if v, ok := global.SystemMonitor.Get(global.SystemMonitor_MEMORY_INFO); ok { + global.Logger.Debugln("读取缓存的的RAM信息") + apiReturn.SuccessData(c, v) + return + } + memoryInfo, err := monitor.GetMemoryInfo() + + if err != nil { + apiReturn.Error(c, "failed") + return + } + + // 缓存 + global.SystemMonitor.Set(global.SystemMonitor_MEMORY_INFO, memoryInfo, cacheSecond*time.Second) + apiReturn.SuccessData(c, memoryInfo) +} + +func (a *MonitorApi) GetDiskStateByPath(c *gin.Context) { + + req := systemApiStructs.MonitorGetDiskStateByPathReq{} + if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil { + apiReturn.ErrorParamFomat(c, err.Error()) + return + } + + cacheDiskName := global.SystemMonitor_DISK_INFO + req.Path + + if v, ok := global.SystemMonitor.Get(cacheDiskName); ok { + global.Logger.Debugln("读取缓存的的RAM信息") + apiReturn.SuccessData(c, v) + return + } + + diskState, err := monitor.GetDiskInfoByPath(req.Path) + if err != nil { + apiReturn.Error(c, "failed") + return + } + + // 缓存 + global.SystemMonitor.Set(cacheDiskName, diskState, cacheSecond*time.Second) + apiReturn.SuccessData(c, diskState) +} diff --git a/service/global/global.go b/service/global/global.go index 20d6910..b24a5c3 100644 --- a/service/global/global.go +++ b/service/global/global.go @@ -35,6 +35,6 @@ var ( Db *gorm.DB RedisDb *redis.Client SystemSetting *systemSetting.SystemSettingCache - SystemMonitor cache.Cacher[ModelSystemMonitor] + SystemMonitor cache.Cacher[interface{}] RateLimit *RateLimiter ) diff --git a/service/global/monitor.go b/service/global/monitor.go index daaa42c..e3e3db7 100644 --- a/service/global/monitor.go +++ b/service/global/monitor.go @@ -1,6 +1,14 @@ package global -import "sun-panel/lib/monitor" +import ( + "sun-panel/lib/monitor" +) + +const ( + SystemMonitor_CPU_INFO = "CPU_INFO" + SystemMonitor_MEMORY_INFO = "MEMORY_INFO" + SystemMonitor_DISK_INFO = "DISK_INFO" +) type ModelSystemMonitor struct { CPUInfo monitor.CPUInfo `json:"cpuInfo"` diff --git a/service/initialize/A_ENTER.go b/service/initialize/A_ENTER.go index 010b732..78abfd7 100644 --- a/service/initialize/A_ENTER.go +++ b/service/initialize/A_ENTER.go @@ -12,7 +12,6 @@ import ( "sun-panel/initialize/other" "sun-panel/initialize/redis" "sun-panel/initialize/runlog" - "sun-panel/initialize/systemMonitor" "sun-panel/initialize/systemSettingCache" "sun-panel/initialize/userToken" "sun-panel/lib/cmn" @@ -90,8 +89,7 @@ func InitApp() error { // 其他的初始化 global.VerifyCodeCachePool = other.InitVerifyCodeCachePool() global.SystemSetting = systemSettingCache.InItSystemSettingCache() - global.SystemMonitor = global.NewCache[global.ModelSystemMonitor](5*time.Hour, -1, "systemMonitorCache") - systemMonitor.Start(global.SystemMonitor, 3*time.Second) + global.SystemMonitor = global.NewCache[interface{}](5*time.Hour, -1, "systemMonitorCache") return nil } diff --git a/service/lib/monitor/monitor.go b/service/lib/monitor/monitor.go index 16c29df..9c19435 100644 --- a/service/lib/monitor/monitor.go +++ b/service/lib/monitor/monitor.go @@ -97,6 +97,20 @@ func GetDiskInfo() ([]DiskInfo, error) { return disks, nil } +func GetDiskInfoByPath(path string) (*DiskInfo, error) { + diskInfo := DiskInfo{} + usage, err := disk.Usage(path) + if err != nil { + return nil, err + } + diskInfo.Free = usage.Free + diskInfo.Mountpoint = usage.Path + diskInfo.Total = usage.Total + diskInfo.Used = usage.Used + diskInfo.UsedPercent = usage.UsedPercent + return &diskInfo, nil +} + // 获取网络统计信息 func GetNetIOCountersInfo() ([]NetIOCountersInfo, error) { netInfo := []NetIOCountersInfo{} diff --git a/service/router/system/monitor.go b/service/router/system/monitor.go index ced3291..43caa02 100644 --- a/service/router/system/monitor.go +++ b/service/router/system/monitor.go @@ -15,5 +15,8 @@ func InitMonitorRouter(router *gin.RouterGroup) { rPublic := router.Group("", middleware.PublicModeInterceptor) { rPublic.POST("/system/monitor/getAll", api.GetAll) + rPublic.POST("/system/monitor/getCpuState", api.GetCpuState) + rPublic.POST("/system/monitor/getDiskStateByPath", api.GetDiskStateByPath) + rPublic.POST("/system/monitor/getMemonyState", api.GetMemonyState) } } From 1474f796fc29051b7e0813839dbb6bdc22293990 Mon Sep 17 00:00:00 2001 From: Sun <95302870@qq.com> Date: Thu, 4 Jan 2024 16:22:33 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=A4=A7=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E5=B0=8F=E5=9B=BE=E6=A0=87=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/systemMonitor.ts | 19 ++ .../AppIconSystemMonitor/CPU.vue | 83 +++++ .../AppIconSystemMonitor/Disk.vue | 93 ++++++ .../AppIconSystemMonitor/Memory.vue | 87 ++++++ .../AppIconSystemMonitor/index.vue | 148 +++++++++ .../deskModule/SystemMonitor/index copy.vue | 171 +++++++++++ .../deskModule/SystemMonitor/index.vue | 286 ++++++++---------- .../deskModule/SystemMonitor/typings.ts | 22 ++ src/views/home/index.vue | 9 +- 9 files changed, 759 insertions(+), 159 deletions(-) create mode 100644 src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue create mode 100644 src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Disk.vue create mode 100644 src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Memory.vue create mode 100644 src/components/deskModule/SystemMonitor/AppIconSystemMonitor/index.vue create mode 100644 src/components/deskModule/SystemMonitor/index copy.vue create mode 100644 src/components/deskModule/SystemMonitor/typings.ts diff --git a/src/api/system/systemMonitor.ts b/src/api/system/systemMonitor.ts index c7f6b20..684c90b 100644 --- a/src/api/system/systemMonitor.ts +++ b/src/api/system/systemMonitor.ts @@ -5,3 +5,22 @@ export function getAll() { url: '/system/monitor/getAll', }) } + +export function getCpuState() { + return post({ + url: '/system/monitor/getCpuState', + }) +} + +export function getDiskStateByPath(path: string) { + return post({ + url: '/system/monitor/getDiskStateByPath', + data: { path }, + }) +} + +export function getMemonyState() { + return post({ + url: '/system/monitor/getMemonyState', + }) +} diff --git a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue new file mode 100644 index 0000000..cd98588 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue @@ -0,0 +1,83 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Disk.vue b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Disk.vue new file mode 100644 index 0000000..15fc9c5 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Disk.vue @@ -0,0 +1,93 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Memory.vue b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Memory.vue new file mode 100644 index 0000000..222bb08 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/Memory.vue @@ -0,0 +1,87 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/index.vue b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/index.vue new file mode 100644 index 0000000..4dda5ec --- /dev/null +++ b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/index.vue @@ -0,0 +1,148 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/index copy.vue b/src/components/deskModule/SystemMonitor/index copy.vue new file mode 100644 index 0000000..7c80e28 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/index copy.vue @@ -0,0 +1,171 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/index.vue b/src/components/deskModule/SystemMonitor/index.vue index d2ccc9a..e11e219 100644 --- a/src/components/deskModule/SystemMonitor/index.vue +++ b/src/components/deskModule/SystemMonitor/index.vue @@ -1,176 +1,152 @@ + + diff --git a/src/components/deskModule/SystemMonitor/typings.ts b/src/components/deskModule/SystemMonitor/typings.ts new file mode 100644 index 0000000..0aee70f --- /dev/null +++ b/src/components/deskModule/SystemMonitor/typings.ts @@ -0,0 +1,22 @@ +export enum MonitorType { + 'cpu' = 'cpu', // 图标风格 + 'memory' = 'memory', // 详情风格 + 'disk' = 'disk', +} + +export interface CardStyle { + background: string +} + +export interface MonitorData { + monitorType: MonitorType + extendParam?: { [key: string]: [value:any] } | any + description?: string + cardStyle: CardStyle +} + +export interface ProgressStyle { + color: string + railColor: string + height: number +} diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 0ee1f6d..9b81d90 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -333,9 +333,6 @@ function handleAddItem(itemIconGroupId?: number) { />
-
- -
--> +
+ +
+
Date: Fri, 5 Jan 2024 13:27:29 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E4=BA=86=E7=BC=96=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/ItemCard/index.vue | 53 +++++++ src/components/common/index.ts | 2 + .../AppIconSystemMonitor/CPU.vue | 47 ++---- .../AppIconSystemMonitor/index.vue | 129 +++++++--------- .../Edit/GenericProgressStyleEditor/index.vue | 84 +++++++++++ .../Edit/ProgressStyleEditor/index.vue | 35 +++++ .../deskModule/SystemMonitor/Edit/index.vue | 68 +++++++++ .../components/GenericMonitorCard/index.vue | 60 ++++++++ .../components/GenericProgress/index.vue | 57 +++++++ .../deskModule/SystemMonitor/index.vue | 139 ++++++++++++------ .../deskModule/SystemMonitor/typings.ts | 7 + src/views/exception/test/zujian.vue | 0 .../home/components/EditItem/IconEditor.vue | 2 + 13 files changed, 520 insertions(+), 163 deletions(-) create mode 100644 src/components/common/ItemCard/index.vue create mode 100644 src/components/deskModule/SystemMonitor/Edit/GenericProgressStyleEditor/index.vue create mode 100644 src/components/deskModule/SystemMonitor/Edit/ProgressStyleEditor/index.vue create mode 100644 src/components/deskModule/SystemMonitor/Edit/index.vue create mode 100644 src/components/deskModule/SystemMonitor/components/GenericMonitorCard/index.vue create mode 100644 src/components/deskModule/SystemMonitor/components/GenericProgress/index.vue create mode 100644 src/views/exception/test/zujian.vue diff --git a/src/components/common/ItemCard/index.vue b/src/components/common/ItemCard/index.vue new file mode 100644 index 0000000..e6b6f9f --- /dev/null +++ b/src/components/common/ItemCard/index.vue @@ -0,0 +1,53 @@ + + + diff --git a/src/components/common/index.ts b/src/components/common/index.ts index 990d2e8..72ff205 100644 --- a/src/components/common/index.ts +++ b/src/components/common/index.ts @@ -8,6 +8,7 @@ import RoundCardModal from './RoundCardModal/index.vue' import SvgIconOnline from './SvgIconOnline/index.vue' import JsonImportExport from './JsonImportExport/index.vue' import AppLoader from './AppLoader/index.vue' +import ItemCard from './ItemCard/index.vue' export { Verification, @@ -20,4 +21,5 @@ export { SvgIconOnline, JsonImportExport, AppLoader, + ItemCard, } diff --git a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue index cd98588..cac1835 100644 --- a/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue +++ b/src/components/deskModule/SystemMonitor/AppIconSystemMonitor/CPU.vue @@ -1,9 +1,9 @@ + + diff --git a/src/components/deskModule/SystemMonitor/Edit/ProgressStyleEditor/index.vue b/src/components/deskModule/SystemMonitor/Edit/ProgressStyleEditor/index.vue new file mode 100644 index 0000000..0a529a6 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/Edit/ProgressStyleEditor/index.vue @@ -0,0 +1,35 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/Edit/index.vue b/src/components/deskModule/SystemMonitor/Edit/index.vue new file mode 100644 index 0000000..da6aa47 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/Edit/index.vue @@ -0,0 +1,68 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/components/GenericMonitorCard/index.vue b/src/components/deskModule/SystemMonitor/components/GenericMonitorCard/index.vue new file mode 100644 index 0000000..6ecdaed --- /dev/null +++ b/src/components/deskModule/SystemMonitor/components/GenericMonitorCard/index.vue @@ -0,0 +1,60 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/components/GenericProgress/index.vue b/src/components/deskModule/SystemMonitor/components/GenericProgress/index.vue new file mode 100644 index 0000000..5848626 --- /dev/null +++ b/src/components/deskModule/SystemMonitor/components/GenericProgress/index.vue @@ -0,0 +1,57 @@ + + + diff --git a/src/components/deskModule/SystemMonitor/index.vue b/src/components/deskModule/SystemMonitor/index.vue index e11e219..c708d2f 100644 --- a/src/components/deskModule/SystemMonitor/index.vue +++ b/src/components/deskModule/SystemMonitor/index.vue @@ -1,21 +1,55 @@