Created
December 8, 2022 06:51
-
-
Save luoyjx/e464c74541e752cef8118d6eb218e07a to your computer and use it in GitHub Desktop.
how to get memory limit in golang server without k8s client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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