topk across multiple metrics

20 views
Skip to first unread message

Pavan Basetty

unread,
Aug 11, 2020, 2:49:48 PM8/11/20
to Prometheus Developers

Hello,

We currently store device rx_bytes and tx_bytes as separate metrics. I am trying to get the topk number of metrics sorted by rx_bytes+tx_bytes, but want to see the actual rx and tx values.

For example, topk(10, sum(increase(rx_bytes[1h])+increase(tx_bytes[1h]))) gives the top 10 devices that have total traffic and the total values (rx+tx).
Is there a way to get the individual rx_bytes and tx_bytes values along with this data? Essentially sort by total traffic, but get the individual metric values.

Appreciate any help with this.

Thanks
-Pavan

Julien Pivotto

unread,
Aug 11, 2020, 2:59:26 PM8/11/20
to Pavan Basetty, Prometheus Developers
On 11 Aug 11:49, Pavan Basetty wrote:
>
> Hello,
>
> We currently store device rx_bytes and tx_bytes as separate metrics. I am
> trying to get the topk number of metrics sorted by rx_bytes+tx_bytes, but
> want to see the actual rx and tx values.
>

Yes:

label_replace(
( label_replace(rx_bytes, "__tmp_name","$1","__name__","(.*)")
or label_replace(tx_bytes, "__tmp_name","$1","__name__","(.*)")
)
and ignoring(__tmp_name) topk(1,rate(rx_bytes[1h]) + rate(tx_bytes[1h])),
"__tmp_name","","","")

> gives the top 10 devices that have total traffic and the total values
> (rx+tx).
> Is there a way to get the individual rx_bytes and tx_bytes values along
> with this data? Essentially sort by total traffic, but get the individual
> metric values.
>
> Appreciate any help with this.
>
> Thanks
> -Pavan
>
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-developers/7a788edb-6003-4017-985b-4f53aa42d633n%40googlegroups.com.


--
Julien Pivotto
@roidelapluie

Pavan Basetty

unread,
Aug 11, 2020, 5:19:01 PM8/11/20
to Pavan Basetty, Prometheus Developers
Thanks Julien, this works.

Is there a way to get the increase in the last 1hour as opposed to the instantaneous values returned above? I tried playing with the syntax, but could not figure it out.

Just to clarify, I am looking for increase(rx_bytes[1h]) increase(tx_bytes[1h]) for the topk series.

Thanks
-Pavan
Reply all
Reply to author
Forward
0 new messages