完成基本的系统监控类库
This commit is contained in:
@@ -12,11 +12,13 @@ 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"
|
||||
"sun-panel/models"
|
||||
"sun-panel/structs"
|
||||
"time"
|
||||
|
||||
"log"
|
||||
|
||||
@@ -88,6 +90,8 @@ 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)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
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() {
|
||||
GetInfo()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user