Filtering results in topk

89 views
Skip to first unread message

BanTheNons

unread,
Aug 20, 2021, 9:21:56 AM8/20/21
to Prometheus Users
I have a graph query, "topk(15, sum(increase(score[$__range])) by (user) / sum(increase(msg_count[$__range])) by (user))". In this instance, users can send messages somewhere, and each time they do that, the "msg_count" counter increases and they get a certain amount of "score". By dividing their total score by their amount of messages, I'm getting the average of how many score they earn per message. From this query, I'm trying to filter out users that have 50 or less messages sent by them. How can I do that?

Brian Candler

unread,
Aug 20, 2021, 10:52:56 AM8/20/21
to Prometheus Users
A few notes:

someexpr > 50

is a filter which will return only those timeseries whose value is over 50. 

A 'timeseries' is distinguished by a metric name and a unique set of labels.

foo / bar

will only give results where the the numerator and denominator have exactly the same set of labels.

So by applying a filter to the denominator only (which is where the message count is), you should be able to get the result you want. Add extra parentheses to make sure the operator precedence isn't a problem.
Reply all
Reply to author
Forward
0 new messages