Files
EdgeNode/internal/utils/system.go

34 lines
535 B
Go
Raw Normal View History

// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package utils
import (
2022-03-12 19:11:29 +08:00
"github.com/shirou/gopsutil/v3/mem"
)
var systemTotalMemory = -1
func init() {
_ = SystemMemoryGB()
}
func SystemMemoryGB() int {
if systemTotalMemory > 0 {
return systemTotalMemory
}
stat, err := mem.VirtualMemory()
if err != nil {
return 0
}
systemTotalMemory = int(stat.Total / 1024 / 1024 / 1024)
2023-03-05 12:34:46 +08:00
if systemTotalMemory <= 0 {
systemTotalMemory = 1
}
setMaxMemory(systemTotalMemory)
return systemTotalMemory
}