Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 750
Jeanluca Scaljeri Avatar asked Sep 19 '19 20:09

Jeanluca Scaljeri


People also ask

What is NaN in Prometheus?

NaN is just a number in Prometheus. Some monitoring systems use NaN as a null or missing value, however in Prometheus NaN is just another floating point value. The way Prometheus represents missing data is to have the data, uhm, missing.

What is TOPK Prometheus?

The topk() function in Prometheus and Loki returns the topk per interval. This means that at time T1, the topk series returned is a different set as that on T2. As a result of this, the graph in Grafana may contain more series in total than what you would expect.

What is counter in Prometheus?

A counter is a cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero on restart. For example, you can use a counter to represent the number of requests served, tasks completed, or errors.

What is AVG by in Prometheus?

Long answer: Prometheus provides two functions for calculating the average: avg_over_time calculates the average over raw sample stored in the database on the lookbehind window specified in square brackets. The average is calculated independently per each matching time series.


1 Answers

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])
like image 127
ConnectionLost Avatar answered Nov 15 '22 11:11

ConnectionLost