PromQL to merge two metrics data

19 views
Skip to first unread message

neel patel

unread,
Jun 22, 2020, 4:44:47 AM6/22/20
to Prometheus Users
Hi,

How can we merge two metrics data in a prometheus query so that grafana will plot it in a single graph rather than individual data.

I am using the below query to plot the data in my dashboard.

system_total_processes{instance=~"$host"}
system_running_processes{instance=~"$host"}

I read the PromQL docs but didn't find anything regarding merging 2 metrics So how to merge both above metrics using a single query so that we can get the data with 2 rows. Any pointers will be appreciated?

Thanks in Advance

Julien Pivotto

unread,
Jun 22, 2020, 4:47:14 AM6/22/20
to neel patel, Prometheus Users
On 22 Jun 14:14, neel patel wrote:
> Hi,
You are looking into adding multiple queries in Grafana. Grafana
supports up to 26 queries per panel.

Look for + Query button:
https://grafana.com/static/img/docs/queries/prometheus-query-editor-7-0.png


regards,


>
> Thanks in Advance
>
> --
> 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/CAPTvBtvbn0wqTnnLKEFrik3fVMu1LOzeOs1rNEaUBi3fpi8wXg%40mail.gmail.com.

--
Julien Pivotto
@roidelapluie

neel patel

unread,
Jun 22, 2020, 5:02:06 AM6/22/20
to neel patel, Prometheus Users
Hi Julien,

Yes, you are right. Thanks for your input. Appreciated.

Thanks,
Neel Patel

Harkishen Singh

unread,
Jun 22, 2020, 2:56:49 PM6/22/20
to Prometheus Users
Either you can go the grafana way, or you can query something smarter like,

{__name__=~"system_.*"}

but that will give you all the queries starting with systems. So, you can add some or/and conditions there as well and make it more productive.

Harkishen Singh

unread,
Jun 22, 2020, 3:12:16 PM6/22/20
to Prometheus Users
Actually, this is the Prometheus way,

{__name__=~"system_total_processes|system_running_processes", instance=~"$host"}

for your use case!

Brian Candler

unread,
Jun 22, 2020, 5:23:53 PM6/22/20
to Prometheus Users
I'd suggest that's not the prometheus way, because it's rare to have two metrics which actually mean exactly the same thing (and if they did, they ought to have the same metric name, and different labels)

Therefore, a single query which mixes multiple metrics into one result set is usually a bad idea.

In this particular instance - total processes and running processes - it might be OK; but even then, if you had (say) 3 systems being shown, which means you get 6 metrics, having them mixed together is usually not useful.
Reply all
Reply to author
Forward
0 new messages