完成基本的系统监控类库

This commit is contained in:
Sun
2024-01-02 22:11:34 +08:00
parent 2e0af5f147
commit c447884d77
6 changed files with 198 additions and 0 deletions
@@ -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
}