Search code examples
prometheus

Calculate Max in value with prometheus


Since I am prometheus-newbie I do not know how to express the question: "What is the maximum number of messages which have been processed per second during the last day". The metric is named messages_in_total

I tried

  • max_over_time(messages_in_total{}[1d]) - but this returns the maximum of the counter value
  • increase(messages_in_total{}[1d])- but this returns the number the counter increased

What I really need would be something like (pseudocode)

  1. Transform range vector which contains absolute messages_in_total to a range vector with which has a value for each second.

  2. get the max out out of it

Example:

  • initial range vector values = (3000,4000, 7000, 8009)
  • adjusted range vector values with rate for each second (values are guessed) = (40, 70, 40)
  • max_value => 70 messages processed per second

Any ideas?


Solution

  • It is possible.

    Example query:

    max_over_time(
       irate( messages_in_total[2m] )[1d:1m]
    )
    

    This will:

    1. take last 1 day
    2. For every 1 minute in that 1 day range it will execute irate( messages_in_total[2m] )
    3. Combine that into range vector
    4. Call max_over_time on all results

    See subquery documentation for more information!