OpenShift - View a pods memory usage (RAM)
by
Jeremy Canfield |
Updated: March 09 2023
| OpenShift articles
The oc get pods command with the --output yaml option can be used to determine the memory and CPU requests and limits for the pod.
oc get pod/foo-9mzm2 --output yaml
Something like this should be returned.
- requests = the amount of memory / CPU that is reserved or allocated for the container. If a container exceeds its memory limit, the container will should be terminated.
- limit = the maximum amount of memory / CPU the container can request. If a container exceeds its memory request, its pod should be evicted if the node the pod is running on runs out of memory.
spec:
containers:
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 10m
memory: 256Mi
The oc exec command can be used to get the real time memory usage in bytes of the pod.
oc exec foo-9mzm2 -- cat /sys/fs/cgroup/memory/memory.usage_in_bytes
Something like this should be returned. In this example, the pod is currently using 568414208 bytes of memory (568 MB).
568414208
And here is how you can return the CPU statistics.
~]$ oc exec foo-9mzm2 -- cat /sys/fs/cgroup/cpu/cpuacct.stat
user 289
system 58
And here is how you could divide the bytes by 1024 to get the value in KB.
~]$ bytes=$(oc exec foo-9mzm2 -- cat /sys/fs/cgroup/memory/memory.usage_in_bytes); echo $(($bytes / 1024))
83180
Or in MB.
~]$ bytes=$(oc exec foo-9mzm2 -- cat /sys/fs/cgroup/memory/memory.usage_in_bytes); echo $(($bytes / 1024 / 1024 ))
96
Did you find this article helpful?
If so, consider buying me a coffee over at