Extracting the total number of target servers defined in Prometheus yaml file.

18 views
Skip to first unread message

Yagyansh S. Kumar

unread,
Mar 3, 2020, 2:10:01 PM3/3/20
to Prometheus Users
I want to get the number of target server that I have been scraping the metrics for. Can this number be dynamic? I mean if I add more servers, the number should increase automatically.
Thanks in advance!

Julien Pivotto

unread,
Mar 3, 2020, 2:12:35 PM3/3/20
to Yagyansh S. Kumar, Prometheus Users
You can get that with the PromQL query:

count(up) by (job)

regards,



--
(o- Julien Pivotto
//\ Open-Source Consultant
V_/_ Inuits - https://www.inuits.eu
signature.asc

Yagyansh S. Kumar

unread,
Mar 3, 2020, 2:27:47 PM3/3/20
to Prometheus Users
If I am not wrong this will give me the number of configured jobs. But there can be more than one target server in a single job, hence, in that case it won't give the total number of target servers.

Julien Pivotto

unread,
Mar 3, 2020, 2:29:45 PM3/3/20
to Yagyansh S. Kumar, Prometheus Users
On 03 Mar 11:27, Yagyansh S. Kumar wrote:
> If I am not wrong this will give me the number of configured jobs. But
> there can be more than one target server in a single job, hence, in that
> case it won't give the total number of target servers.

It gives you the number of targets per job. Usually servers will be in
one job, e.g. node.

>
> On Wednesday, March 4, 2020 at 12:42:35 AM UTC+5:30, Julien Pivotto wrote:
> >
> > On 03 Mar 11:10, Yagyansh S. Kumar wrote:
> > > I want to get the number of target server that I have been scraping the
> > > metrics for. Can this number be dynamic? I mean if I add more servers,
> > the
> > > number should increase automatically.
> > > Thanks in advance!
> >
> >
> > You can get that with the PromQL query:
> >
> > count(up) by (job)
> >
> > regards,
> >
> >
> >
> > --
> > (o- Julien Pivotto
> > //\ Open-Source Consultant
> > V_/_ Inuits - https://www.inuits.eu
> >
>
> --
> 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/9fb896c6-5629-4352-8cb0-1587a1e5e842%40googlegroups.com.
signature.asc

Yagyansh S. Kumar

unread,
Mar 3, 2020, 2:35:09 PM3/3/20
to Prometheus Users
Okay, understood.
Thanks for the quick help.

On Wednesday, March 4, 2020 at 12:59:45 AM UTC+5:30, Julien Pivotto wrote:
On 03 Mar 11:27, Yagyansh S. Kumar wrote:
> If I am not wrong this will give me the number of configured jobs. But
> there can be more than one target server in a single job, hence, in that
> case it won't give the total number of target servers.

It gives you the number of targets per job. Usually servers will be in
one job, e.g. node.

>
> On Wednesday, March 4, 2020 at 12:42:35 AM UTC+5:30, Julien Pivotto wrote:
> >
> > On 03 Mar 11:10, Yagyansh S. Kumar wrote:
> > > I want to get the number of target server that I have been scraping the
> > > metrics for. Can this number be dynamic? I mean if I add more servers,
> > the
> > > number should increase automatically.
> > > Thanks in advance!
> >
> >
> > You can get that with the PromQL query:
> >
> >     count(up) by (job)
> >
> > regards,
> >
> >
> >
> > --
> >  (o-    Julien Pivotto
> >  //\    Open-Source Consultant
> >  V_/_   Inuits - https://www.inuits.eu
> >
>
> --
> 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.
Reply all
Reply to author
Forward
0 new messages