mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-06 10:00:25 +08:00
将获取系统内存函数放入到utils中
This commit is contained in:
27
internal/utils/system.go
Normal file
27
internal/utils/system.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/shirou/gopsutil/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)
|
||||
return systemTotalMemory
|
||||
}
|
||||
Reference in New Issue
Block a user