<p>Looking for example how to monitor Container Memory Usage with Prometheus.</p>
<p>It reports all the containers ok if we using this query:</p>
<pre><code>(container_memory_usage_bytes / container_spec_memory_limit_bytes) * 100 &gt; 90
</code></pre>
<p>However works ok if container does not have a memory limit defined.    The the divisor is 0, and the results are +Inf, meaning that the alert triggers incorrectly since +Inf matches &gt; 90.</p>
<p>Any suggestions how to properly use Container Memory Usage monitoring?</p>

user3360847
<p>I asked the same question from a different perspective just a few days earlier <a href="https://stackoverflow.com/questions/64168412/how-to-formulate-query-x-y-and-y-0-correctly">here</a>. So far I have not found an answer. I have settled with adding another label <code>has_memory_limit</code> that I use to only alert on containers that have a limit defined.</p>
<hr />
<p><strong>Okay, I have figured it out:</strong></p>
<pre><code>((container_memory_usage_bytes / container_spec_memory_limit_bytes) != +Inf)  * 100 &gt; 52
</code></pre>
<p>Since positive infinity, negative infinity and NaN are numbers in <a href="https://www.robustperception.io/get-thee-to-a-nannary" rel="nofollow noreferrer">Prometheus</a>, you can simply filter them out with <code>!= +Inf</code>.</p>
