Understanding a prometheus query for memory free (node-exporter)

Viewed 239

can anyone help me understand a query from prometheus with data from node-exporter?

I have taken a query from the community, it is the following - notice the "1 -" in front of the full query. This is the query I obtained.

(1 - (node_memory_MemAvailable_bytes{node_type=~"mining"} / (node_memory_MemTotal_bytes{node_type=~"mining"})))* 100 > 75

I don't understand why the "1-" is there. This particular query right now returns 2 results.

I removed the "1-" like so

(node_memory_MemAvailable_bytes{node_type=~"mining"} / (node_memory_MemTotal_bytes{node_type=~"mining"}))* 100 > 75

Now the query returns 4 results.

I am a little confused at which is correct and why would the "1-" be before the query.

Here is a screenshot showing the prometheus query results

Could anybody help or explain and maybe I am missing something.

enter image description here

1 Answers

The correct is the first (with the "1-"), the "mathmagic" is explained following.

We have:

MemUsed = MemTotal - MemAvailable

So:

% MemUsed = ((MemTotal - MemAvailble) / MemTotal) * 100

Simplifying we have:

% MemUsed = (MemTotal / MemTotal - MemAvailable / MemTotal) * 100

And finally:

% MemUsed = (1 - MemAvailable / MemTotal) * 100
Related