16Bitt / kubemem

A small binary to probe memory usage in a kubernetes pod
43 stars 10 forks source link

Track RSS memory instead of total #4

Open mattgrayisok opened 2 years ago

mattgrayisok commented 2 years ago

Currently the total used memory is pulling from /sys/fs/cgroup/memory/memory.usage_in_bytes which provides the total used memory, including reclaimable caches. K8s uses the RSS memory (or something approximate to it) when calculating memory use for evictions. This is throwing the % calculation out by a significant factor, causing pods to be flagged as failed before k8s would consider them to be in any OOMKiller danger.

The RSS for the cgroup can be pulled from /sys/fs/cgroup/memory/memory.stat but the parsing is a bit more challenging. The last time I wrote any C was about 15 years ago but I managed to cobble something together which uses a regex to match the appropriate line and adjust the calculation accordingly.

Fancy a PR?

vladsf commented 5 months ago

Try submitting a PR.