mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
		
			443 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			443 B
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2021 GoEdge CDN goedge.cdn@gmail.com. All rights reserved.
 | 
						|
 | 
						|
package utils
 | 
						|
 | 
						|
import (
 | 
						|
	"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)
 | 
						|
	return systemTotalMemory
 | 
						|
}
 |