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?
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:
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 1count(...)-> counts the number of elements in the vector (ie the number of users). You could also usesumhere instead ofcount, since all of the values are 1, it would give the same result. I don't know if there's a performance difference.