HTTP API request for querying multiple metrics

96 views
Skip to first unread message

Hakim Kahlouche

unread,
Mar 11, 2020, 6:00:15 PM3/11/20
to Prometheus Users
Hi,
Is it possible to fetch time-series for multiple metric names using one single HTTP API query request, or is there a restriction of one HTTP request per metric name?

Let's say I want to query :

query=go_memstats_gc_cpu_fraction and node_cpu_seconds_total 

Is it possible to query those two metrics with one single HTTP request? If so, how could I do that?

Thank you!
--
Hakim

Christian Hoffmann

unread,
Mar 11, 2020, 6:25:41 PM3/11/20
to Hakim Kahlouche, Prometheus Users
Hi,

On 3/11/20 11:00 PM, Hakim Kahlouche wrote:
> Is it possible to fetch time-series for multiple metric names using one
> single HTTP API query request, or is there a restriction of one HTTP
> request per metric name?
>
> Let's say I want to query :
>
> *query=go_memstats_gc_cpu_fraction _and_ node_cpu_seconds_total *
> *
> *
> Is it possible to query those two metrics with one single HTTP request?
> If so, how could I do that?

What exactly are you trying to do?

It is possible to make PromQL queries which use calculations based on
multiple metrics. There is "and", "or" and other operators.

If you want to get the raw data via the API instead, you might have
better luck by using the federate endpoint:
https://prometheus.io/docs/prometheus/latest/federation/


Kind regards,
Christian

Hakim Kahlouche

unread,
Mar 11, 2020, 6:38:11 PM3/11/20
to Prometheus Users
Thanks for your reply.

My question is about the PromQL calculation on metrics.

Let's say I want to query the following:


Can I send one HTTP request only to fetch both metrics? That means, I would receive a JSON with two time-series.

Is that possible?
Thanks

Brian Candler

unread,
Mar 12, 2020, 4:43:14 AM3/12/20
to Prometheus Users
On Wednesday, 11 March 2020 22:38:11 UTC, Hakim Kahlouche wrote:
Thanks for your reply.

My question is about the PromQL calculation on metrics.

Let's say I want to query the following:


Can I send one HTTP request only to fetch both metrics? That means, I would receive a JSON with two time-series.

Is that possible?

You seem to be asking two different questions:

1. Can I use promQL to perform calculations between two different metrics?
2. Can I fetch two different metrics at once, and perform my own calculations on the raw data?

Answer to 1 is "yes".  The easiest calculations are between time series which have exactly the same set of labels, but you can do more sophisticated queries which match metrics based on subsets of labels.

Answer to 2 is "yes", but as already said, you'd normally not use the "query" endpoint for this, you'd be better using the "federate" endpoint which can explicitly filter to the set of metrics you're interested in.

Hakim Kahlouche

unread,
Mar 12, 2020, 10:13:06 AM3/12/20
to Prometheus Users
Thanks for the reply.

I still have one small follow up question regarding "Answer to 2":
My question is in the context where I do NOT have another Prometheus on the client side to fetch with Federation, I just have an independant HTTP client that uses the remote HTTP API of Prometheus to fetch the metrics.

Follow-up Question: In this context, can my HTTP client use one HTTP request to fetch two different metrics at once or that is not possible?

Thanks a lot!

Brian Candler

unread,
Mar 12, 2020, 12:14:50 PM3/12/20
to Prometheus Users
The /federate endpoint *is* part of the HTTP API.  Just think of it as another query interface.
(It just happens also to be how one prometheus server queries another, but it's not limited to that)
Reply all
Reply to author
Forward
0 new messages