What is the PromQL for MAU (Monthly Active Users)?

31 Views Asked by At

What is the PromQL query to calculate the monthly active users (MAU) based on the user dimension/label in the latency Histogram metric ServiceLevelIndicator_milliseconds_count?

I want to create a graph that shows the number of unique users over time.

Is there a PromQL equivalent to the SQL query SELECT COUNT(DISTINCT user) FROM ServiceLevelIndicator_milliseconds_count WHERE time BETWEEN @from AND @to?

1

There are 1 best solutions below

2
echatman On

That is going to be a very slow query and I encourage you to add a new metric to more directly track this information. That said, here's my best attempt at it:

count(group(present_over_time(ServiceLevelIndicator_milliseconds_count[30d])) by (user))

Breaking it down to explain the parts:

  • present_over_time(ServiceLevelIndicator_milliseconds_count[30d]) -> takes the last 30 days of data and converts from a range vector to an instant vector (discarding the timestamps and metric values, preserving the labels)
  • group(...) by (user) -> groups by user so now you have one element per user, all with a value of 1
  • count(...) -> counts the number of elements in the vector (ie the number of users). You could also use sum here instead of count, since all of the values are 1, it would give the same result. I don't know if there's a performance difference.