Why is PromQL rate() returning one value?

184 Views Asked by At

I'm trying to calculate the MIN/MAX/AVG of the CPU usage of a pod using the rate function, but rate() is only returning a single value.

Here is the command to get the CPU usage in seconds and the values from the response of the container_cpu_usage_seconds_total metric:

curl -s -G "http://master-1.ocp9.pd.f5net.com:30355/api/v1/query" --data-urlencode "query=container_cpu_usage_seconds_total{namespace='arka-ingress', pod='f5ingress-f5ingress-55ff78b955-bjhbc', container=''}[12h:1h]" | jq

"values": [
  [
    1685746800,
    "233.925484799"
  ],
  [
    1685750400,
    "245.503601613"
  ],
  [
    1685754000,
    "257.245759184"
  ],
  [
    1685757600,
    "268.81255512"
  ],
  [
    1685761200,
    "280.711385953"
  ],
  [
    1685764800,
    "292.226109825"
  ],
  [
    1685768400,
    "304.090964418"
  ],
  [
    1685772000,
    "315.670226267"
  ],
  [
    1685775600,
    "327.400741452"
  ],
  [
    1685779200,
    "339.122179483"
  ],
  [
    1685782800,
    "350.865870242"
  ]
]

When I query using the rate function around it, it should return a list of the rates of change, but it only returns a single value.

curl -s -G "http://master-1.ocp9.pd.f5net.com:30355/api/v1/query" --data-urlencode "query=rate(container_cpu_usage_seconds_total{namespace='arka-ingress', pod='f5ingress-f5ingress-55ff78b955-bjhbc', container=''}[12h:1h])" | jq

"value": [
  1685786028.71,
  "0.003085077907426099"
]

Why is this happening?


UPDATE: The query now returns the correct response:

curl -s -G "http://master-1.ocp9.pd.f5net.com:30355/api/v1/query_range" --data-urlencode "query=rate(container_cpu_usage_seconds_total{namespace='arka-ingress', pod='f5ingress-f5ingress-55ff78b955-bjhbc', container=''}[5m]) * 1000" --data-urlencode "start=1685811600" --data-urlencode "end=1685811660" --data-urlencode "step=15s" | jq

0

There are 0 best solutions below