Files
EdgeNode/internal/nodes/node_status_executor_unix.go

58 lines
1.3 KiB
Go
Raw Normal View History

//go:build !windows
2020-09-09 18:53:53 +08:00
package nodes
import (
2020-10-25 21:27:38 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
2021-04-29 16:48:47 +08:00
"github.com/TeaOSLab/EdgeNode/internal/monitor"
"github.com/iwind/TeaGo/maps"
2022-03-12 19:11:29 +08:00
"github.com/shirou/gopsutil/v3/load"
"github.com/shirou/gopsutil/v3/mem"
2020-09-09 18:53:53 +08:00
)
// 更新内存
2020-10-25 21:27:38 +08:00
func (this *NodeStatusExecutor) updateMem(status *nodeconfigs.NodeStatus) {
2020-09-09 18:53:53 +08:00
stat, err := mem.VirtualMemory()
if err != nil {
return
}
// 重新计算内存
if stat.Total > 0 {
stat.Used = stat.Total - stat.Free - stat.Buffers - stat.Cached
status.MemoryUsage = float64(stat.Used) / float64(stat.Total)
}
status.MemoryTotal = stat.Total
2021-04-29 16:48:47 +08:00
// 记录监控数据
monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemMemory, maps.Map{
"usage": status.MemoryUsage,
"total": status.MemoryTotal,
"used": stat.Used,
})
2020-09-09 18:53:53 +08:00
}
// 更新负载
2020-10-25 21:27:38 +08:00
func (this *NodeStatusExecutor) updateLoad(status *nodeconfigs.NodeStatus) {
2020-09-09 18:53:53 +08:00
stat, err := load.Avg()
if err != nil {
status.Error = err.Error()
return
}
if stat == nil {
status.Error = "load is nil"
return
}
status.Load1m = stat.Load1
status.Load5m = stat.Load5
status.Load15m = stat.Load15
2021-04-29 16:48:47 +08:00
// 记录监控数据
monitor.SharedValueQueue.Add(nodeconfigs.NodeValueItemLoad, maps.Map{
"load1m": status.Load1m,
"load5m": status.Load5m,
"load15m": status.Load15m,
})
2020-09-09 18:53:53 +08:00
}