How to query Multiple Metric with PromQL

3,428 views
Skip to first unread message

Mạnh Nguyễn Tiến

unread,
Sep 11, 2019, 5:36:55 AM9/11/19
to Prometheus Users
I have many Query Request using PromQL like:
- Collect disk read rate: sum by (instance) (irate(node_disk_read_bytes_total[2m])) / 1024 / 1024
- Collect CPU Available:  (avg by(instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
If just with metrics, I can do it using operator "|": 
http://Prometheus_IP_Address/api/v1/query?query={__name__=~”node_memory_Buffers_bytes|node_cpu_seconds_total”,instance=”Node_Exporter_IPAddress”}

But with PromQL I cannot. Please help me, how can I collect all query request above with only one Query Request.

tgug...@redhat.com

unread,
Sep 11, 2019, 5:50:16 AM9/11/19
to Mạnh Nguyễn Tiến, Prometheus Users
Have you tried using the "or" operator to combine these two queries?
> --
> 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/2e914d5d-34d9-4650-866f-1be77a62deeb%40googlegroups.com
> .
--
Tobias Guggenmos
Software Engineering Intern

Red Hat GmbH
Engeldamm 64b
10179 Berlin
tgug...@redhat.com

Red Hat GmbH, http://www.de.redhat.com/, Sitz: Grasbrunn,
Handelsregister: Amtsgericht München, HRB 153243,
Geschäftsführer: Charles Cachera, Michael O'Neill, Tom Savage, Eric
Shander

Mạnh Nguyễn Tiến

unread,
Sep 11, 2019, 6:02:04 AM9/11/19
to Prometheus Users
I tried, but the operator "or" will return just one value with "or" of multiple values from multiple queries.

Prometheus Query.PNG



Vào 16:50:16 UTC+7 Thứ Tư, ngày 11 tháng 9 năm 2019, tgug...@redhat.com đã viết:
Have you tried using the "or" operator to combine these two queries? 

On Wed, 2019-09-11 at 02:36 -0700, Mạnh Nguyễn Tiến wrote: 
> I have many Query Request using PromQL like: 
> - Collect disk read rate: sum by (instance) 
> (irate(node_disk_read_bytes_total[2m])) / 1024 / 1024 
> - Collect CPU Available:  (avg by(instance) 
> (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) 
> If just with metrics, I can do it using operator "|": 
> http://Prometheus_IP_Address/api/v1/query?query={__name__=~”node_memory_Buffers_bytes|node_cpu_seconds_total”,instance=”Node_Exporter_IPAddress”} 
> But with PromQL I cannot. Please help me, how can I collect all query 
> request above with only one Query Request. 
> -- 
> 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 promethe...@googlegroups.com

tgug...@redhat.com

unread,
Sep 11, 2019, 7:59:33 AM9/11/19
to Mạnh Nguyễn Tiến, Prometheus Users
Oops, missed that.

That's because both queries get exactly the same label set in their
responses. You can work around that by adding an additional label to
each result and then combine them using or:

label_replace(sum by (instance) (irate(node_disk_read_bytes_total[2m]))
/ 1024 / 1024, "device", "disk", "instance", ".*") or label_replace(avg
by(instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100,
"device", "cpu", "instance", ".*")

On Wed, 2019-09-11 at 03:02 -0700, Mạnh Nguyễn Tiến wrote:
> I tried, but the operator "or" will return just one value with "or"
> of multiple values from multiple queries.
>
>
>
> send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/prometheus-users/ba05cf8f-ce65-4b5d-9864-49536ae77b1c%40googlegroups.com
> .

Reply all
Reply to author
Forward
0 new messages