-1

Based on this answer I was trying to obtain peak CPU usage during last minute averaged over many servers. Here is my query:

max_over_time(sum(1-rate(node_cpu_seconds_total{mode="idle",instance!="epgp003:9401"}[1m]))by(instance))

However I get this error:

Error executing query: invalid parameter "query": 1:15: parse error: expected type range vector in call to function "max_over_time", got instant vector.

If I try this:

max_over_time((sum(1-rate(node_cpu_seconds_total{mode="idle",instance!="epgp003:9401"})[1m:]))by(instance))

I get this error:

Error executing query: invalid parameter "query": 1:107: parse error: unexpected <by>

Following query:

max_over_time((sum(1-rate(node_cpu_seconds_total{mode="idle",instance!="epgp003:9401"}[1m]))by(instance))[1m:])

Yields an array of values as response, while I need only one number (the maximum).

user1876484
  • 610
  • 6
  • 16
  • 1
    You need range selector within max_over_time too. Something like [1m:]. Notice since this is nota vector selectors, you need to use subquery syntax (plus you might need additional parenthesis before range) – markalex Jul 20 '23 at 08:50
  • @markalex - thank you! Actually I tried that also (updated my original question). Pay attention to `instance!="epgp003:9401"` - those are many servers (because of `!=`). – user1876484 Jul 20 '23 at 09:08
  • 1
    To get biggest of them you can enclose your query (working one obviously) into `max( ... )`. – markalex Jul 20 '23 at 11:55
  • I did that and it seemed to work: `max(sum(1-rate(node_cpu_seconds_total{mode="idle",instance!="epgp003:9401"}[1m]))by(instance))`. I just hope it shows what I need. Thank you! – user1876484 Jul 20 '23 at 14:13

1 Answers1

1

I believe, correct query will be:

max(
 max_over_time(
  (sum(
   1-rate(
      node_cpu_seconds_total{mode="idle",instance!="epgp003:9401"}
      [1m])
   ) by (instance)
  )[1m:]
 )
)

Here we first apply max_over_time over range of 1 minute, to find max value for each server over that time. And then - apply max to get a single maximum value among those.

markalex
  • 8,623
  • 2
  • 7
  • 32