Hi!
I’ve been trying to get the number of distinct users currently using my application using Loki.
I’ve got a user_id
field in my logs, and the idea is to count the number of distinct values within a time period.
I came across multiple topics related to the subject, but most of them were closed without a proper answer (Creating log-based metric to count unique field values in logs, Count number of unique values for a key, and others I can’t link because the forum blocks me ). I have found one potential solution to this problem, but I’m not sure if it gives me the correct result, and it seems to be awfully inefficient as the query can’t seem to work for time ranges longer than one minute.
count(count by(user_id) (rate({service_name="my-app"} [1m])))
Are there, by any chance, better solutions for that? I considered “Unwrapped range aggregations” by my lack of experience in LogQL seem to prevent me from using them correctly
Thanks in advance!