I currently have these three PromQL queries:
CPU Sum:
curl -s -G "http://10.192.248.10:30000/api/v1/query" --data-urlencode "query=sum_over_time(container_cpu_usage_seconds_total{pod='f5ingress-f5ingress-55ff78b955-vqxch', namespace='arka-ingress'}[10m])" | jq
CPU Average:
curl -s -G "http://10.192.248.10:30000/api/v1/query" --data-urlencode "query=avg_over_time(container_cpu_usage_seconds_total{pod='f5ingress-f5ingress-55ff78b955-vqxch', namespace='arka-ingress'}[10m])" | jq
CPU Datapoints:
curl -s -G "http://10.192.248.10:30000/api/v1/query" --data-urlencode "query=container_cpu_usage_seconds_total{pod='f5ingress-f5ingress-55ff78b955-vqxch', namespace='arka-ingress'}[10m]" | jq
I technically have two questions:
- For the 'CPU Datapoints' query, how can I pass in the 'step' parameter? For example, in the query it uses a time window of 10m, how can I specify how many datapoints I want the function to return in that window?
- How can I get the CPU usage at a specific point in time? The only CPU query I see in PromQL is container_cpu_usage_seconds_total. Is this possible?
The
container_cpu_usage_seconds_totalmetric shows cumulative CPU time used by the givencontainersince the start ofcadvisor- see these docs.This is so called counter metric type.
If you want obtaining the real CPU usage at the given time, then use rate() function. For example, the following command would return the average CPU usage over the last 5 minutes for every running container at the given timestamp
1685665200:This command sends the query to instant query API provided by Prometheus. This API returns a single calculated point at the given
timeper each time series, which match the given filter.If you need obtaining multiple calculated points per each matching time series on the given time range, then take a look at range query API.