<p>We have our web api service running in OpenShift for the past few months</p>
<p>When we deployed this to OpenShift, initially we have given basic request and limits for memory and CPU.</p>
<p>Sometime when the resource limit crossed its threshold we had to increase the limit</p>
<p>We have several services deployed and we have given some random request and limits for the Pod.
we are trying to figure out a way to provide resource limits and request based on the past few months that it is running on OpenShift</p>
<p>My idea is to look at the last few months on requests what is POD is receiving and come up with a value to requests and limits</p>
<p>I am thinking PROMQL can help me to provide this value, can someone help me with a query to determine average resource and limits based on past 4 to 5 weeks of requests on the POD ?</p>

<p>Try the below queries which are helpful in your case :</p>
<pre><code>avg (  
  avg_over_time(container_cpu_usage_seconds_total:rate5m[30d])
) by (pod_name)
</code></pre>
<p>The above query is used  to determine the average CPU usage of a certain pod for the past 30 days.</p>
<pre><code>avg (  
  avg_over_time(container_memory_usage_seconds_total:rate5m[30d])
) by (pod_name)
</code></pre>
<p>The above query is used  to determine the average memory usage of a certain pod for the past 30 days.</p>
<p>In the query avg is used to calculate the average of the sample values in the input series, grouped by their <code>[pod_name]</code>. <code>avg_over_time</code> is used for getting the average value of all points in the specified interval, we can get the metrics like cpu and memory usage for the specified interval by using the respective queries.</p>
<p>For more info follow this <a href="https://prometheus.io/docs/prometheus/latest/querying/functions/#aggregation_over_time" rel="nofollow noreferrer">doc</a>.</p>
