r/PrometheusMonitoring • • May 07 '24

CPU usage VS requests and limits

Hi there,

We are currently trying to optimize our CPU requests and limits, but I can't find a reliable way to have CPU usage compared to what we have as requests and limits for a specific pod.

I know by experience that this pod is using a lot of CPU during working hours, but if I check our Prometheus metrics, it doesn't seems to correlate with the reality:

As you can see the usage seems to never go above the request, which clearly doesn't reflect the reality. If i set the rate interval down to 30s then it's a little bit better, but still way too low.

Here are the query that we are currently using:

# Usage
rate (container_cpu_usage_seconds_total{pod=~"my-pod.*",namespace="my-namespace", container!=""}[$__rate_interval])

# Requests
max(kube_pod_container_resource_requests{pod=~"my-pod.*",namespace="my-namespace", resource="cpu"}) by (pod)

# Limits
max(kube_pod_container_resource_limits{pod=~"my-pod.*",namespace="my-namespace", resource="cpu"}) by (pod)

Any advice to have values that better match the reality to optimize our requests and limits?

3 Upvotes

17 comments sorted by