Bootstrap FreeKB - OpenShift - View a pods memory usage (RAM)
OpenShift - View a pods memory usage (RAM)

Updated:   |  OpenShift articles

While it is possible to determine the amount of memory being used by a pod on the command line, I almost never use the command line for this, and instead use the OpenShift console. This is just something that is so much easier to do using the console.

In the OpenShift console, at Home > Projects select the project/namespace that contains the pod. Then select Pods and select the pod. Then select the Metrics tab and the Memory usage graph will be displayed. You can then click on the Memory usage graph to get a more details graph of the pods memory usage.

 

Or, 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/my-pod-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 my-pod-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 my-pod-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 my-pod-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 Buy Me A Coffee



Comments


Add a Comment


Please enter 0110d0 in the box below so that we can be sure you are a human.