shivcena
shivcena

Reputation: 2053

Need guidance for prometheus memory utilization query

I am using the prometheus query '100 - ((node_memory_MemAvailable_bytes{job="jobname"} * 100) / node_memory_MemTotal_bytes{job="jobname"})' to get the memory utilization and it is working fine.

The above query is giving the result for current memory utilization.

I need to reconstruct the query to get the memory utilization for last 1 hour.For example, if the memory utilization reaches more than 10 MB at 9.15 am and the current memory utilization is 2 MB at 10 am, now i need to check whether the memory utilization is more than 9 MB between 9 am to 10 am

kindly guide me how to construct the prometheus query for it, i think it is something like, '(100 - ((node_memory_MemAvailable_bytes{job="jobname"} * 100) / node_memory_MemTotal_bytes{job="jobname"}))>9[1H]'

Upvotes: 1

Views: 1217

Answers (2)

valyala
valyala

Reputation: 17830

Probably you need SLI value answering the question: how much time the jobname used more than 90% of memory over the last hour? Then the following PromQL query should answer the question:

avg_over_time(
    ((1 - node_memory_MemAvailable_bytes{job="jobname"} /
    node_memory_MemTotal_bytes{job="jobname"}) >bool 0.9)[1h:1m]
)

The returned value will be in the range [0..1], where 0 means 0% (i.e. memory usage didn't exceed 90% during the last hour), while 1 means 100% (i.e. memory usage was higher than 90% all the time during the last hour).

The query uses the following PromQL features:

Upvotes: 4

shivcena
shivcena

Reputation: 2053

100 - ((node_memory_MemAvailable_bytes{job="jobname"} * 100) / node_memory_MemTotal_bytes{job="jobname"})[30m:1m]

This will list the memory utilization values for every 1 minute

Upvotes: 0

Related Questions