<p>I have my python program running on k8s pod. The program reads data in pandas dataframe from the db &amp; do some data transformation operations. In one of the operation, data size grows exponentially causing pod out of memory error. Since it's pandas, all data is held in the memory.</p>
<p>To avoid this, I am required to write the data to the disk if memory consumption crosses the threshold. And to do this, I need to know the current pod memory utilization inside my python program so that as soon as threshold reaches, say 90%, I start dumping data to disk &amp; freeing memory.</p>
<p>Basically I need to know pod memory utilization inside my python program.</p>
<p>Any suggestions?
Thanks in advance.</p>

<p>In container, you need to get cgroup's memory.</p>
<pre><code> ls /sys/fs/cgroup/memory/
</code></pre>
<p>In container: <code>cat /sys/fs/cgroup/memory/memory.usage_in_bytes</code> to get memory usage.</p>
<p>Or in host: <code>/sys/fs/cgroup/memory/docker/[containerId]/memory.usage_in_bytes</code></p>
<p><a href="https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt" rel="noreferrer">https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt</a></p>
