2020-09-09 18:53:53 +08:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
|
|
package nodes
|
|
|
|
|
|
|
|
|
|
import (
|
2020-10-25 21:27:38 +08:00
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
2020-09-09 18:53:53 +08:00
|
|
|
"github.com/shirou/gopsutil/load"
|
|
|
|
|
"github.com/shirou/gopsutil/mem"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 更新内存
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新负载
|
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
|
|
|
|
|
}
|