Alert when a container is close to using its memory limit.
I'm using the
cadvisor agent, which gives me two useful metrics:
- container_memory_usage_bytes : how much memory a container is using
- container_spec_memory_limit_bytes : what is the memory limit I've defined for that container
Using these, I can answer the question "what percent of its memory limit has this container used?" using this expression:
...to tell me when the container is using more than 90% of its allocated memory.
Problem:
Everything above works fine, except when a container does not have a memory limit defined. Then the divisor is 0, and the result is +Inf, meaning that the alert triggers incorrectly since +Inf matches > 90.
Is there a way I can either exclude metrics where container_spec_memory_limit_bytes = 0, or provide a range for the alert such that +Inf values don't trigger it? Or perhaps I should rewrite this query altogether?