From 4c1d67b51313882030894d8078b75bcdf1262324 Mon Sep 17 00:00:00 2001 From: Sun <95302870@qq.com> Date: Tue, 9 Jan 2024 14:03:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=201.3.0-beta24-01-09=20Squas?= =?UTF-8?q?hed=20commit=20of=20the=20following:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 53d1f382c5142f6a388b2d3fa13caef04a48db91 Author: Sun <95302870@qq.com> Date: Tue Jan 9 11:54:33 2024 +0800 系统状态标题加上阴影,beta版本最终优化 commit fc56328765b8a4d902b59f2393f43e10f3c3dac5 Author: Sun <95302870@qq.com> Date: Mon Jan 8 22:37:24 2024 +0800 磁盘监控增加表单验证 commit 3905717d420d8339e0d04443a79e69229cd10a1a Author: Sun <95302870@qq.com> Date: Mon Jan 8 22:36:10 2024 +0800 删除无用文件 commit 89b6b633107832465973656abfdb6e25be156747 Author: Sun <95302870@qq.com> Date: Mon Jan 8 21:10:10 2024 +0800 修改翻译文件为json格式(为了方便引用插件)优化过期登录弹窗多个的问题 commit 2efb31571ebe5997113c75e69f973dd436cef985 Author: Sun <95302870@qq.com> Date: Mon Jan 8 13:56:57 2024 +0800 增加vscode工作区文件 commit bc79b661db2defa36bdfadb13b1038e906e36d7e Author: Sun <95302870@qq.com> Date: Mon Jan 8 13:56:45 2024 +0800 暂时解决依赖循环的问题 commit a24520f8087a45abe08ee7ea864169888754a5fc Author: Sun <95302870@qq.com> Date: Sun Jan 7 20:07:52 2024 +0800 修改设置里面壁纸提示词错误的问题修改首页默认标题 commit 394c6ce20ce33cd3edf43b33ac7c1f5b23cfe89a Author: Sun <95302870@qq.com> Date: Sun Jan 7 14:53:53 2024 +0800 适配多语言 Squashed commit of the following: commit 632f86c0228c68391c01865c7576f3aa0408c102 Author: Sun <95302870@qq.com> Date: Sun Jan 7 14:47:55 2024 +0800 退出的时候清除appstore commit b9d805e49a3c6b2ad38bc8d527cb12cc8709012e Author: Sun <95302870@qq.com> Date: Sun Jan 7 13:55:20 2024 +0800 系统状态监控适配国际化 commit daece99723ec96d210241d2ca4e5a85dc5ae69bd Author: Sun <95302870@qq.com> Date: Sun Jan 7 13:09:46 2024 +0800 适配添加项目页面的国际化配置还有时钟的星期* commit 8ea2b2fe951f6266415c96a197cb8d00faef4058 Author: Sun <95302870@qq.com> Date: Sun Jan 7 12:01:55 2024 +0800 完成适配所有apps国际化 commit 21ef54e0d4afb10f560c8cb7aff666374afe0f87 Author: Sun <95302870@qq.com> Date: Sat Jan 6 21:36:07 2024 +0800 增加读取默认浏览器语言 commit 6f710bbebe63ab2800193f27c71e5c0034f11978 Author: Sun <95302870@qq.com> Date: Sat Jan 6 21:09:58 2024 +0800 登录页面增加语言选择选项 commit cb7c4a89a160ed3ef91ad566ec98e75325e7601f Author: Sun <95302870@qq.com> Date: Sat Jan 6 20:37:16 2024 +0800 首次尝试增加英文语言,并在我的信息设置 commit fb996e17cd11611d30c0e12feee00ddf7b225e32 Author: Sun <95302870@qq.com> Date: Sat Jan 6 18:22:40 2024 +0800 完成基础设置页面的语言国际化适配 commit ffc378a38fa4221a9240b067660614ab43009325 Author: Sun <95302870@qq.com> Date: Sat Jan 6 17:35:13 2024 +0800 增加完善基本配置中的系统状态开关 commit c91eaf3e941dfa91b7feca925109ec7121874fda Merge: 7ebe358 a60f72c Author: Sun <95302870@qq.com> Date: Sat Jan 6 12:57:05 2024 +0800 Merge branch 'feature/monitor2' into dev commit 7ebe35856e423bb10d8078636b0c80e472203a68 Merge: d3e3cf5 779712a Author: Sun <95302870@qq.com> Date: Sat Jan 6 12:56:15 2024 +0800 Merge branch 'feature/footer' into dev commit a60f72c2779a4adee77f4ab161fb4fad21ff0611 Author: Sun <95302870@qq.com> Date: Sat Jan 6 12:55:04 2024 +0800 优化了首页 commit 899c945fff12290f3c81348a3c262400b1a0ce15 Author: Sun <95302870@qq.com> Date: Sat Jan 6 12:54:19 2024 +0800 完成系统监控 commit cdf16277ff85cee5029de3b7ea78b14bc0274623 Author: Sun <95302870@qq.com> Date: Sat Jan 6 12:41:38 2024 +0800 增加删除功能 commit 128af005ebc95b73ecef8873301a61556984fbea Author: Sun <95302870@qq.com> Date: Sat Jan 6 11:56:32 2024 +0800 完成排序保存功能 commit 3f4b3c67f261f21121c8e9f7c14d926f152a5836 Author: Sun <95302870@qq.com> Date: Sat Jan 6 11:46:59 2024 +0800 初步完成了增改查包括磁盘状态 commit a85d90985df45af75f8fbc165021b160d5e6500d Author: Sun <95302870@qq.com> Date: Fri Jan 5 22:19:47 2024 +0800 增加磁盘信息卡片的适配 commit c955afd86134b38620a884e9e6540eda398392e4 Author: Sun <95302870@qq.com> Date: Fri Jan 5 21:36:38 2024 +0800 增加获取磁盘挂载点接口 commit 21e8e8f1b872a7e7989c45b29061f52127dffce5 Author: Sun <95302870@qq.com> Date: Fri Jan 5 21:14:57 2024 +0800 基础完成了增改查cpu和内存状态 commit bdbcd50aa1b1b6958043e26be5b705430312c64c Author: Sun <95302870@qq.com> Date: Fri Jan 5 14:25:09 2024 +0800 优化公共入口组件 commit 9735e67a7d6334e39d4f58b053c32b3be25e7fa8 Author: Sun <95302870@qq.com> Date: Fri Jan 5 14:01:46 2024 +0800 适配三个组件 commit 3a82949afc64147209be046f9298d55096abd0c3 Author: Sun <95302870@qq.com> Date: Fri Jan 5 13:58:58 2024 +0800 优化组件 commit 0d0421c8ebc749889422c416970fd5760f2a5f6a Author: Sun <95302870@qq.com> Date: Fri Jan 5 13:27:29 2024 +0800 初步完成了编辑器 commit 1474f796fc29051b7e0813839dbb6bdc22293990 Author: Sun <95302870@qq.com> Date: Thu Jan 4 16:22:33 2024 +0800 完成大图标小图标切换 commit baf64a927280fdb04579d5afeff1b5d50e56556a Author: Sun <95302870@qq.com> Date: Thu Jan 4 12:08:39 2024 +0800 增加获取各项监控的单独api commit d3e3cf5d58168cad1e2fa3c96e2381c21aabcab4 Author: Sun <95302870@qq.com> Date: Wed Jan 3 20:46:58 2024 +0800 尝试将所有监控放在顶部 commit 8dfec7e4b78cc393fad96df9d452c5f2dd4933bb Author: Sun <95302870@qq.com> Date: Wed Jan 3 20:02:03 2024 +0800 完整横条显示并对容量尺寸单位优化自动识别 commit fe967a93141472970616a5eac416c59510810b64 Author: Sun <95302870@qq.com> Date: Wed Jan 3 18:55:39 2024 +0800 适配显示了cpu、硬盘、内存信息 commit 11ea134be3ce8aca9c1bf6af4610e3bb4e09eca7 Author: Sun <95302870@qq.com> Date: Tue Jan 2 23:14:04 2024 +0800 完成系统监控的基础api接口 commit c447884d77349553864e0e045b83b3a4b67345da Author: Sun <95302870@qq.com> Date: Tue Jan 2 22:11:34 2024 +0800 完成基本的系统监控类库 commit 779712a5da617fa090056a5d549145f687d8db54 Author: Sun <95302870@qq.com> Date: Tue Jan 2 17:14:16 2024 +0800 增加自定义footer --- .vscode/settings.json | 8 +- index.html | 2 +- .../apiData/systemApiStructs/monitor.go | 5 + service/api/api_v1/system/A_ENTER.go | 1 + service/api/api_v1/system/monitor.go | 96 ++++++ service/assets/version | 2 +- service/global/global.go | 1 + service/global/monitor.go | 18 + service/initialize/A_ENTER.go | 2 + .../initialize/systemMonitor/systemMonitor.go | 53 +++ service/lib/cache/base.go | 5 + service/lib/monitor/monitor.go | 149 +++++++++ service/router/system/A_ENTER.go | 1 + service/router/system/monitor.go | 23 ++ src/api/system/systemMonitor.ts | 32 ++ .../svg-icons/clarity-hard-disk-solid.svg | 1 + src/assets/svg-icons/ion-language.svg | 1 + .../material-symbols-memory-alt-rounded.svg | 1 + src/assets/svg-icons/solar-cpu-bold.svg | 1 + src/components/apps/About/index.vue | 14 +- src/components/apps/ImportExport/index.vue | 56 ++-- src/components/apps/ItemGroupManage/index.vue | 29 +- src/components/apps/Style/index.vue | 94 ++++-- src/components/apps/UserInfo/index.vue | 49 ++- src/components/common/ItemCard/index.vue | 53 +++ src/components/common/index.ts | 2 + src/components/deskModule/Clock/index.vue | 15 +- .../AppIconSystemMonitor/CPU.vue | 59 ++++ .../AppIconSystemMonitor/Disk.vue | 69 ++++ .../AppIconSystemMonitor/Memory.vue | 64 ++++ .../AppIconSystemMonitor/index.vue | 118 +++++++ .../SystemMonitor/Edit/DiskEditor/index.vue | 163 +++++++++ .../Edit/GenericProgressStyleEditor/index.vue | 101 ++++++ .../deskModule/SystemMonitor/Edit/index.vue | 148 +++++++++ .../deskModule/SystemMonitor/common.ts | 88 +++++ .../components/GenericMonitorCard/index.vue | 61 ++++ .../components/GenericProgress/index.vue | 57 ++++ .../deskModule/SystemMonitor/index.vue | 308 ++++++++++++++++++ .../deskModule/SystemMonitor/typings.ts | 33 ++ src/components/deskModule/index.ts | 3 +- src/enums/panel/index.ts | 1 + src/locales/en-US.json | 246 ++++++++++++++ src/locales/en-US.ts | 94 ------ src/locales/index.ts | 17 +- src/locales/zh-CN.json | 245 ++++++++++++++ src/locales/zh-CN.ts | 121 ------- src/store/modules/app/helper.ts | 11 +- src/store/modules/app/index.ts | 7 +- src/store/modules/moduleConfig/index.ts | 4 +- src/store/modules/panel/helper.ts | 7 + src/typings/panel.d.ts | 4 + src/typings/systemMonitor.d.ts | 43 +++ src/utils/cmn/index.ts | 8 + src/utils/defaultData/index.ts | 17 + src/utils/request/index.ts | 15 +- .../index.vue => exception/test/zujian.vue} | 0 .../home/components/AppStarter/index.vue | 18 +- .../home/components/EditItem/IconEditor.vue | 23 +- src/views/home/components/EditItem/index.vue | 52 +-- src/views/home/index.vue | 67 ++-- src/views/login/index.vue | 23 +- sun-panel.code-workspace | 84 +++++ 62 files changed, 2696 insertions(+), 397 deletions(-) create mode 100644 service/api/api_v1/common/apiData/systemApiStructs/monitor.go create mode 100644 service/api/api_v1/system/monitor.go create mode 100644 service/global/monitor.go create mode 100644 service/initialize/systemMonitor/systemMonitor.go create mode 100644 service/lib/monitor/monitor.go create mode 100644 service/router/system/monitor.go create mode 100644 src/api/system/systemMonitor.ts create mode 100644 src/assets/svg-icons/clarity-hard-disk-solid.svg create mode 100644 src/assets/svg-icons/ion-language.svg create mode 100644 src/assets/svg-icons/material-symbols-memory-alt-rounded.svg create mode 100644 src/assets/svg-icons/solar-cpu-bold.svg create mode 100644 src/components/common/ItemCard/index.vue 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/Edit/DiskEditor/index.vue create mode 100644 src/components/deskModule/SystemMonitor/Edit/GenericProgressStyleEditor/index.vue create mode 100644 src/components/deskModule/SystemMonitor/Edit/index.vue create mode 100644 src/components/deskModule/SystemMonitor/common.ts 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/components/deskModule/SystemMonitor/index.vue create mode 100644 src/components/deskModule/SystemMonitor/typings.ts create mode 100644 src/locales/en-US.json delete mode 100644 src/locales/en-US.ts create mode 100644 src/locales/zh-CN.json delete mode 100644 src/locales/zh-CN.ts create mode 100644 src/typings/systemMonitor.d.ts create mode 100644 src/utils/defaultData/index.ts rename src/views/{home/applist/index.vue => exception/test/zujian.vue} (100%) create mode 100644 sun-panel.code-workspace diff --git a/.vscode/settings.json b/.vscode/settings.json index a161def..4da5073 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,16 +19,12 @@ "markdown" ], "cSpell.words": [ - "antfu", "axios", "bumpp", - "chatgpt", - "chenzhaoyu", "commitlint", "davinci", "dockerhub", "esno", - "GPTAPI", "highlightjs", "hljs", "iconify", @@ -39,7 +35,6 @@ "mdhljs", "mila", "nodata", - "OPENAI", "pinia", "Popconfirm", "rushstack", @@ -50,8 +45,7 @@ "Typecheck", "unplugin", "VITE", - "vueuse", - "Zhao" + "vueuse" ], "i18n-ally.enabledParsers": [ "ts" diff --git a/index.html b/index.html index b8f7493..24e2ca0 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ - Sun Panel + Sun-Panel 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/A_ENTER.go b/service/api/api_v1/system/A_ENTER.go index f1b8636..490e69e 100644 --- a/service/api/api_v1/system/A_ENTER.go +++ b/service/api/api_v1/system/A_ENTER.go @@ -9,4 +9,5 @@ type ApiSystem struct { RegisterApi RegisterApi NoticeApi NoticeApi ModuleConfigApi ModuleConfigApi + MonitorApi MonitorApi } diff --git a/service/api/api_v1/system/monitor.go b/service/api/api_v1/system/monitor.go new file mode 100644 index 0000000..7a14d2c --- /dev/null +++ b/service/api/api_v1/system/monitor.go @@ -0,0 +1,96 @@ +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) + return + } + 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("读取缓存的的DISK信息") + 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) +} + +func (a *MonitorApi) GetDiskMountpoints(c *gin.Context) { + if list, err := monitor.GetDiskMountpoints(); err != nil { + apiReturn.Error(c, err.Error()) + return + } else { + apiReturn.SuccessData(c, list) + } +} diff --git a/service/assets/version b/service/assets/version index 58ba41a..0a8912e 100644 --- a/service/assets/version +++ b/service/assets/version @@ -1 +1 @@ -8|1.2.1 \ No newline at end of file +9|1.3.0-beta24-01-09 \ No newline at end of file diff --git a/service/global/global.go b/service/global/global.go index 0e133c6..b24a5c3 100644 --- a/service/global/global.go +++ b/service/global/global.go @@ -35,5 +35,6 @@ var ( Db *gorm.DB RedisDb *redis.Client SystemSetting *systemSetting.SystemSettingCache + SystemMonitor cache.Cacher[interface{}] RateLimit *RateLimiter ) diff --git a/service/global/monitor.go b/service/global/monitor.go new file mode 100644 index 0000000..e3e3db7 --- /dev/null +++ b/service/global/monitor.go @@ -0,0 +1,18 @@ +package global + +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"` + DiskInfo []monitor.DiskInfo `json:"diskInfo"` + NetIOCountersInfo []monitor.NetIOCountersInfo `json:"netIOCountersInfo"` + MemoryInfo monitor.MemoryInfo `json:"memoryInfo"` +} diff --git a/service/initialize/A_ENTER.go b/service/initialize/A_ENTER.go index 449561f..78abfd7 100644 --- a/service/initialize/A_ENTER.go +++ b/service/initialize/A_ENTER.go @@ -17,6 +17,7 @@ import ( "sun-panel/lib/cmn" "sun-panel/models" "sun-panel/structs" + "time" "log" @@ -88,6 +89,7 @@ func InitApp() error { // 其他的初始化 global.VerifyCodeCachePool = other.InitVerifyCodeCachePool() global.SystemSetting = systemSettingCache.InItSystemSettingCache() + global.SystemMonitor = global.NewCache[interface{}](5*time.Hour, -1, "systemMonitorCache") return nil } diff --git a/service/initialize/systemMonitor/systemMonitor.go b/service/initialize/systemMonitor/systemMonitor.go new file mode 100644 index 0000000..1b155f1 --- /dev/null +++ b/service/initialize/systemMonitor/systemMonitor.go @@ -0,0 +1,53 @@ +package systemMonitor + +import ( + "sun-panel/global" + "sun-panel/lib/cache" + "sun-panel/lib/monitor" + "time" +) + +func Start(cacher cache.Cacher[global.ModelSystemMonitor], interval time.Duration) { + go func() { + + ticker := time.NewTicker(interval) + defer ticker.Stop() + + for { + select { + case <-ticker.C: + go func() { + monitorInfo := GetInfo() + // jsonByte, _ := json.Marshal(monitorInfo) + // fmt.Println("系统监控:", string(jsonByte)) + cacher.SetDefault("value", monitorInfo) + }() + } + } + + }() + +} + +func GetInfo() global.ModelSystemMonitor { + + var modelSystemMonitor global.ModelSystemMonitor + + if cpuInfo, err := monitor.GetCPUInfo(); err == nil { + modelSystemMonitor.CPUInfo = cpuInfo + } + + if v, err := monitor.GetDiskInfo(); err == nil { + modelSystemMonitor.DiskInfo = v + } + + if v, err := monitor.GetNetIOCountersInfo(); err == nil { + modelSystemMonitor.NetIOCountersInfo = v + } + + if v, err := monitor.GetMemoryInfo(); err == nil { + modelSystemMonitor.MemoryInfo = v + } + + return modelSystemMonitor +} diff --git a/service/lib/cache/base.go b/service/lib/cache/base.go index b522d70..99dbf1e 100644 --- a/service/lib/cache/base.go +++ b/service/lib/cache/base.go @@ -4,6 +4,11 @@ import ( "time" ) +const ( + CACHE_DRIVE_REDIS = "redis" + CACHE_DRIVE_MEMORY = "memory" +) + // 缓存接口-支持Redis和内存使用 type Cacher[T any] interface { // 设置 diff --git a/service/lib/monitor/monitor.go b/service/lib/monitor/monitor.go new file mode 100644 index 0000000..72c2904 --- /dev/null +++ b/service/lib/monitor/monitor.go @@ -0,0 +1,149 @@ +package monitor + +import ( + "time" + + "github.com/shirou/gopsutil/v3/cpu" + "github.com/shirou/gopsutil/v3/disk" + "github.com/shirou/gopsutil/v3/mem" + "github.com/shirou/gopsutil/v3/net" +) + +type CPUInfo struct { + CoreCount int32 `json:"coreCount"` + CPUNum int `json:"cpuNum"` + Model string `json:"model"` + Usages []float64 `json:"usages"` +} + +type DiskInfo struct { + Mountpoint string `json:"mountpoint"` + Total uint64 `json:"total"` + Used uint64 `json:"used"` + Free uint64 `json:"free"` + UsedPercent float64 `json:"usedPercent"` +} + +type NetIOCountersInfo struct { + BytesSent uint64 `json:"bytesSent"` + BytesRecv uint64 `json:"bytesRecv"` + Name string `json:"name"` +} + +type MemoryInfo struct { + Total uint64 `json:"total"` + Free uint64 `json:"free"` + Used uint64 `json:"used"` + UsedPercent float64 `json:"usedPercent"` +} + +// 获取CPU信息 +func GetCPUInfo() (CPUInfo, error) { + cpuInfoRes := CPUInfo{} + cpuInfo, err := cpu.Info() + + if err == nil && len(cpuInfo) > 0 { + cpuInfoRes.CoreCount = cpuInfo[0].Cores + cpuInfoRes.Model = cpuInfo[0].ModelName + } + numCPU, _ := cpu.Counts(true) + cpuInfoRes.CPUNum = numCPU + cpuPercentages, err := cpu.Percent(time.Second, true) + cpuInfoRes.Usages = cpuPercentages + + return cpuInfoRes, err +} + +// 获取内存信息 单位:MB +func GetMemoryInfo() (MemoryInfo, error) { + memoryInfo := MemoryInfo{} + // 获取内存信息 + memInfo, err := mem.VirtualMemory() + if err == nil { + memoryInfo.Free = memInfo.Free + memoryInfo.Total = memInfo.Total + memoryInfo.Used = memInfo.Used + memoryInfo.UsedPercent = memInfo.UsedPercent + } + + return memoryInfo, err +} + +// 获取每个磁盘分区使用情况 +func GetDiskInfo() ([]DiskInfo, error) { + disks := []DiskInfo{} + // 获取所有磁盘分区的信息 + partitions, err := disk.Partitions(true) + if err != nil { + return disks, err + } + + for _, partition := range partitions { + usage, err := disk.Usage(partition.Mountpoint) + if err != nil { + // fmt.Printf("Error getting disk usage for %s: %v\n", partition.Mountpoint, err) + continue + } + + disks = append(disks, DiskInfo{ + Mountpoint: partition.Mountpoint, + Total: usage.Total / 1024 / 1024, + Used: usage.Used / 1024 / 1024, + Free: usage.Free / 1024 / 1024, + UsedPercent: usage.UsedPercent, + }) + } + + return disks, nil +} + +func GetDiskMountpoints() ([]disk.PartitionStat, error) { + return disk.Partitions(true) +} + +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{} + netStats, err := net.IOCounters(true) + if err == nil { + for _, netStat := range netStats { + netInfo = append(netInfo, NetIOCountersInfo{ + BytesRecv: netStat.BytesRecv, + BytesSent: netStat.BytesSent, + Name: netStat.Name, + }) + + } + } + return netInfo, err +} + +// func GetCountDiskInfo() { +// // 获取所有磁盘的总使用情况 +// allUsage, err := disk.Usage("/") +// if err != nil { +// fmt.Printf("Error getting total disk usage: %v\n", err) +// return +// } + +// // 打印所有磁盘的总使用情况 +// fmt.Println("Total Disk Usage:") +// fmt.Printf("Total: %d MB\n", allUsage.Total/1024/1024) +// fmt.Printf("Used: %d MB\n", allUsage.Used/1024/1024) +// fmt.Printf("Free: %d MB\n", allUsage.Free/1024/1024) +// fmt.Printf("Usage: %.2f%%\n", allUsage.UsedPercent) +// } diff --git a/service/router/system/A_ENTER.go b/service/router/system/A_ENTER.go index 62e8b7c..c65dedf 100644 --- a/service/router/system/A_ENTER.go +++ b/service/router/system/A_ENTER.go @@ -11,4 +11,5 @@ func Init(routerGroup *gin.RouterGroup) { InitRegister(routerGroup) InitNoticeRouter(routerGroup) InitModuleConfigRouter(routerGroup) + InitMonitorRouter(routerGroup) } diff --git a/service/router/system/monitor.go b/service/router/system/monitor.go new file mode 100644 index 0000000..d4f3ff0 --- /dev/null +++ b/service/router/system/monitor.go @@ -0,0 +1,23 @@ +package system + +import ( + "sun-panel/api/api_v1" + "sun-panel/api/api_v1/middleware" + + "github.com/gin-gonic/gin" +) + +func InitMonitorRouter(router *gin.RouterGroup) { + api := api_v1.ApiGroupApp.ApiSystem.MonitorApi + r := router.Group("", middleware.LoginInterceptor) + r.POST("/system/monitor/getDiskMountpoints", api.GetDiskMountpoints) + + // 公开模式 + 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) + } +} diff --git a/src/api/system/systemMonitor.ts b/src/api/system/systemMonitor.ts new file mode 100644 index 0000000..0e17ff2 --- /dev/null +++ b/src/api/system/systemMonitor.ts @@ -0,0 +1,32 @@ +import { post } from '@/utils/request' + +export function getAll() { + return post({ + 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', + }) +} + +export function getDiskMountpoints() { + return post({ + url: '/system/monitor/getDiskMountpoints', + }) +} diff --git a/src/assets/svg-icons/clarity-hard-disk-solid.svg b/src/assets/svg-icons/clarity-hard-disk-solid.svg new file mode 100644 index 0000000..f97333e --- /dev/null +++ b/src/assets/svg-icons/clarity-hard-disk-solid.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/svg-icons/ion-language.svg b/src/assets/svg-icons/ion-language.svg new file mode 100644 index 0000000..0a25377 --- /dev/null +++ b/src/assets/svg-icons/ion-language.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/svg-icons/material-symbols-memory-alt-rounded.svg b/src/assets/svg-icons/material-symbols-memory-alt-rounded.svg new file mode 100644 index 0000000..0f5dcfa --- /dev/null +++ b/src/assets/svg-icons/material-symbols-memory-alt-rounded.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/svg-icons/solar-cpu-bold.svg b/src/assets/svg-icons/solar-cpu-bold.svg new file mode 100644 index 0000000..590f39d --- /dev/null +++ b/src/assets/svg-icons/solar-cpu-bold.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/apps/About/index.vue b/src/components/apps/About/index.vue index 4de4cab..381dce9 100644 --- a/src/components/apps/About/index.vue +++ b/src/components/apps/About/index.vue @@ -35,7 +35,7 @@ onMounted(() => { @@ -43,19 +43,23 @@ onMounted(() => {
- QQ交流群:276594668 + {{ $t('apps.about.issue') }}Github Issues +
+ +
+ {{ $t('apps.about.QQGroup') }}{{ $t("apps.about.addQQGroupUrl") }} | - 二维码(推荐) + {{ $t('apps.about.QR') }}
- 开发者:红烧猎人 | 🧧打赏 + {{ $t('apps.about.author') }}红烧猎人 | {{ $t('apps.about.donate') }}
diff --git a/src/components/apps/ImportExport/index.vue b/src/components/apps/ImportExport/index.vue index 47a17d5..59d9caf 100644 --- a/src/components/apps/ImportExport/index.vue +++ b/src/components/apps/ImportExport/index.vue @@ -91,9 +91,9 @@ async function importIcons(): Promise { } catch (error) { if (error instanceof Error) - return `发生错误: ${error.message}` + return `${t('common.failed')}: ${error.message}` else - return '发生未知错误' + return t('common.unknownError') } } @@ -162,7 +162,7 @@ function handleFileChange(options: { file: UploadFileInfo; fileList: Array