Skip to content

Instantly share code, notes, and snippets.

@luoyjx
Created December 8, 2022 06:51
Show Gist options
  • Save luoyjx/e464c74541e752cef8118d6eb218e07a to your computer and use it in GitHub Desktop.
Save luoyjx/e464c74541e752cef8118d6eb218e07a to your computer and use it in GitHub Desktop.
how to get memory limit in golang server without k8s client
// Open the cgroup hierarchy of the current container
f, err := os.Open("/sys/fs/cgroup/memory/memory.limit_in_bytes")
if err != nil {
// Handle error
}
defer f.Close()
// Read the maximum memory limit from the file
var maxMemLimit int64
_, err = fmt.Fscanf(f, "%d", &maxMemLimit)
if err != nil {
// Handle error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment