Script Refactoring

pull/2148/head
skiffer-git 2 years ago
parent 84174a1e59
commit 847dd8fe9e

@ -8,4 +8,4 @@ declare -A binaries=(
)
tool_binaries=("ncpu" "infra")
tool_binaries=("ncpu" "infra" "check-free-memory")

@ -0,0 +1,27 @@
package main
import (
"fmt"
"os"
"syscall"
)
func main() {
var sysInfo syscall.Sysinfo_t
err := syscall.Sysinfo(&sysInfo)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get system info: %v\n", err)
os.Exit(-1)
}
// Sysinfo returns memory in bytes, convert it to gigabytes
freeMemoryGB := float64(sysInfo.Freeram) / float64(1024*1024*1024)
if freeMemoryGB < 4.0 {
fmt.Fprintf(os.Stderr, "System free memory is less than 4GB: %.2fGB\n", freeMemoryGB)
os.Exit(-1)
} else {
fmt.Printf("System free memory is sufficient: %.2fGB\n", freeMemoryGB)
}
}
Loading…
Cancel
Save