On 03 Mar 15:15, Александр Мороз wrote:
> I'm trying to understand how to get only unique values from prometheus
>
> For example:
>
> from this
> cool_metic{label="foo",instance="machine1"..} 5555
> cool_metic{label="foo",instance="machine2"..} 5555
> cool_metic{label="bar",instance="machine3"..} 3333
> cool_metic{label="foo",instance="machine4"..} 5555
> cool_metic{label="bar",instance="machine5"..} 3333
> cool_metic{label="xxx",instance="machine6"..} 1111
>
> i need to get something like this
> cool_metic{label="foo"..} 5555
> cool_metic{label="bar"..} 3333
> cool_metic{label="xxx"..} 1111
This is a very interesting challenge!!
max without(instance) (cool_metic) + 0*count(topk by(__values) (1,count_values("__values",cool_metic) without(instance)))without(__values)
If you do not want to exclude the instance label:
cool_metic+0*count(topk by(__values) (1,count_values("__values",cool_metic) without()))without(__values)
>
> I found a page on stackoverflow
> <
https://stackoverflow.com/questions/53193459/prometheus-query-equivalent-to-sql-distinct>
> where it is done through avg(sum(.... but it seems to me this is not the
> best solution and maybe there is a more correct way to do it.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
prometheus-use...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/prometheus-users/5cb378a8-84b0-4550-91af-bfe313541ff1%40googlegroups.com.
--
(o- Julien Pivotto
//\ Open-Source Consultant
V_/_ Inuits -
https://www.inuits.eu