复制项目
This commit is contained in:
26
tools/check-free-memory/main.go
Normal file
26
tools/check-free-memory/main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
)
|
||||
|
||||
func main() {
|
||||
vMem, err := mem.VirtualMemory()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to get virtual memory info: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Use the Available field to get the available memory
|
||||
availableMemoryGB := float64(vMem.Available) / float64(1024*1024*1024)
|
||||
|
||||
if availableMemoryGB < 1.0 {
|
||||
fmt.Fprintf(os.Stderr, "System available memory is less than 1GB: %.2fGB\n", availableMemoryGB)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Printf("System available memory is sufficient: %.2fGB\n", availableMemoryGB)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user