Search code examples
prometheusmetricspromql

How to divide two Prometheus Counters


I have two metrics, Counters to be precise, lets say they are called

  • NumberOfVisitors
  • NumberOfLogins

In grafana I would like to plot is the number-of-logins divided by the number of visitors (or the other way around) over time. So I tried

rate(NumberOfLogins) / rate(NumberOfVisitors)

but this results in an error

Error executing query: invalid parameter 'query': parse error at char 46: expected type range vector in call to function "rate", got instant vector

I'm not sure what all that means. Hopefully something like this is possible. Any help would be appreciated


Solution

  • The rate function expect a range vector, for example:

    rate(NumberOfLogins[5m])
    

    That means to calcualte the rate within the last 5 minutes at each time point. You can change the 5m to other time range.

    Therefore this would fit you need:

    rate(NumberOfLogins[5m]) / rate(NumberOfVisitors[5m])