更新 1.3.0-beta24-01-09

Squashed commit of the following:

commit 53d1f382c5
Author: Sun <95302870@qq.com>
Date:   Tue Jan 9 11:54:33 2024 +0800

    系统状态标题加上阴影,beta版本最终优化

commit fc56328765
Author: Sun <95302870@qq.com>
Date:   Mon Jan 8 22:37:24 2024 +0800

    磁盘监控增加表单验证

commit 3905717d42
Author: Sun <95302870@qq.com>
Date:   Mon Jan 8 22:36:10 2024 +0800

    删除无用文件

commit 89b6b63310
Author: Sun <95302870@qq.com>
Date:   Mon Jan 8 21:10:10 2024 +0800

    修改翻译文件为json格式(为了方便引用插件)优化过期登录弹窗多个的问题

commit 2efb31571e
Author: Sun <95302870@qq.com>
Date:   Mon Jan 8 13:56:57 2024 +0800

    增加vscode工作区文件

commit bc79b661db
Author: Sun <95302870@qq.com>
Date:   Mon Jan 8 13:56:45 2024 +0800

    暂时解决依赖循环的问题

commit a24520f808
Author: Sun <95302870@qq.com>
Date:   Sun Jan 7 20:07:52 2024 +0800

    修改设置里面壁纸提示词错误的问题修改首页默认标题

commit 394c6ce20c
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 ffc378a38f
Author: Sun <95302870@qq.com>
Date:   Sat Jan 6 17:35:13 2024 +0800

    增加完善基本配置中的系统状态开关

commit c91eaf3e94
Merge: 7ebe358 a60f72c
Author: Sun <95302870@qq.com>
Date:   Sat Jan 6 12:57:05 2024 +0800

    Merge branch 'feature/monitor2' into dev

commit 7ebe35856e
Merge: d3e3cf5 779712a
Author: Sun <95302870@qq.com>
Date:   Sat Jan 6 12:56:15 2024 +0800

    Merge branch 'feature/footer' into dev

commit a60f72c277
Author: Sun <95302870@qq.com>
Date:   Sat Jan 6 12:55:04 2024 +0800

    优化了首页

commit 899c945fff
Author: Sun <95302870@qq.com>
Date:   Sat Jan 6 12:54:19 2024 +0800

    完成系统监控

commit cdf16277ff
Author: Sun <95302870@qq.com>
Date:   Sat Jan 6 12:41:38 2024 +0800

    增加删除功能

commit 128af005eb
Author: Sun <95302870@qq.com>
Date:   Sat Jan 6 11:56:32 2024 +0800

    完成排序保存功能

commit 3f4b3c67f2
Author: Sun <95302870@qq.com>
Date:   Sat Jan 6 11:46:59 2024 +0800

    初步完成了增改查包括磁盘状态

commit a85d90985d
Author: Sun <95302870@qq.com>
Date:   Fri Jan 5 22:19:47 2024 +0800

    增加磁盘信息卡片的适配

commit c955afd861
Author: Sun <95302870@qq.com>
Date:   Fri Jan 5 21:36:38 2024 +0800

    增加获取磁盘挂载点接口

commit 21e8e8f1b8
Author: Sun <95302870@qq.com>
Date:   Fri Jan 5 21:14:57 2024 +0800

    基础完成了增改查cpu和内存状态

commit bdbcd50aa1
Author: Sun <95302870@qq.com>
Date:   Fri Jan 5 14:25:09 2024 +0800

    优化公共入口组件

commit 9735e67a7d
Author: Sun <95302870@qq.com>
Date:   Fri Jan 5 14:01:46 2024 +0800

    适配三个组件

commit 3a82949afc
Author: Sun <95302870@qq.com>
Date:   Fri Jan 5 13:58:58 2024 +0800

    优化组件

commit 0d0421c8eb
Author: Sun <95302870@qq.com>
Date:   Fri Jan 5 13:27:29 2024 +0800

    初步完成了编辑器

commit 1474f796fc
Author: Sun <95302870@qq.com>
Date:   Thu Jan 4 16:22:33 2024 +0800

    完成大图标小图标切换

commit baf64a9272
Author: Sun <95302870@qq.com>
Date:   Thu Jan 4 12:08:39 2024 +0800

    增加获取各项监控的单独api

commit d3e3cf5d58
Author: Sun <95302870@qq.com>
Date:   Wed Jan 3 20:46:58 2024 +0800

    尝试将所有监控放在顶部

commit 8dfec7e4b7
Author: Sun <95302870@qq.com>
Date:   Wed Jan 3 20:02:03 2024 +0800

    完整横条显示并对容量尺寸单位优化自动识别

commit fe967a9314
Author: Sun <95302870@qq.com>
Date:   Wed Jan 3 18:55:39 2024 +0800

    适配显示了cpu、硬盘、内存信息

commit 11ea134be3
Author: Sun <95302870@qq.com>
Date:   Tue Jan 2 23:14:04 2024 +0800

    完成系统监控的基础api接口

commit c447884d77
Author: Sun <95302870@qq.com>
Date:   Tue Jan 2 22:11:34 2024 +0800

    完成基本的系统监控类库

commit 779712a5da
Author: Sun <95302870@qq.com>
Date:   Tue Jan 2 17:14:16 2024 +0800

    增加自定义footer
This commit is contained in:
Sun
2024-01-09 14:03:03 +08:00
parent 2e0af5f147
commit 4c1d67b513
62 changed files with 2696 additions and 397 deletions
@@ -0,0 +1,5 @@
package systemApiStructs
type MonitorGetDiskStateByPathReq struct {
Path string `json:"path"`
}
+1
View File
@@ -9,4 +9,5 @@ type ApiSystem struct {
RegisterApi RegisterApi
NoticeApi NoticeApi
ModuleConfigApi ModuleConfigApi
MonitorApi MonitorApi
}
+96
View File
@@ -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)
}
}
+1 -1
View File
@@ -1 +1 @@
8|1.2.1
9|1.3.0-beta24-01-09
+1
View File
@@ -35,5 +35,6 @@ var (
Db *gorm.DB
RedisDb *redis.Client
SystemSetting *systemSetting.SystemSettingCache
SystemMonitor cache.Cacher[interface{}]
RateLimit *RateLimiter
)
+18
View File
@@ -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"`
}
+2
View File
@@ -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
}
@@ -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
}
+5
View File
@@ -4,6 +4,11 @@ import (
"time"
)
const (
CACHE_DRIVE_REDIS = "redis"
CACHE_DRIVE_MEMORY = "memory"
)
// 缓存接口-支持Redis和内存使用
type Cacher[T any] interface {
// 设置
+149
View File
@@ -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)
// }
+1
View File
@@ -11,4 +11,5 @@ func Init(routerGroup *gin.RouterGroup) {
InitRegister(routerGroup)
InitNoticeRouter(routerGroup)
InitModuleConfigRouter(routerGroup)
InitMonitorRouter(routerGroup)
}
+23
View File
@@ -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)
}
}