how to get count of no.of instance

131 views
Skip to first unread message

Sameer Modak

unread,
May 24, 2024, 11:53:33 AM5/24/24
to Prometheus Users
Hello Team,

I want to know the no of instance data sending to prometheus. How do i formulate the query .


Basically i have below working query but issues is we have 6  instances hence its summing value of all instances. Instead we just need value from one instance.
sum(kafka_consumergroup_lag{cluster=~"$cluster",consumergroup=~"$consumergroup",topic=~"$topic"})by (consumergroup, topic)
I was thinking to divide it / 6 but it has to be variabalise on runtime
if 3 exporters are running then it value/3 to get exact value.

Ben Kochie

unread,
May 25, 2024, 2:23:44 AM5/25/24
to Sameer Modak, Prometheus Users
You can use the `up` metric

sum(...)
/
count(up{job="kafka"})

--
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/fa5f309f-779f-45f9-b5a0-430b75ff0884n%40googlegroups.com.

Sameer Modak

unread,
May 26, 2024, 3:28:10 AM5/26/24
to Prometheus Users
I tried the same i m not getting any data post adding below 

sum(kafka_consumergroup_lag{cluster=~"$cluster",consumergroup=~"$consumergroup",topic=~"$topic"}) by (consumergroup, topic) / count(up{job="prometheus.scrape.kafka_exporter"})

Brian Candler

unread,
May 26, 2024, 3:54:10 AM5/26/24
to Prometheus Users
The labels for the two sides of the division need to match exactly.

If they match 1:1 except for additional labels, then you can use
xxx / on (foo,bar) yyy   # foo,bar are the matching labels
or
xxx / ignoring (baz,qux) zzz   # baz,qux are the labels to ignore

If they match N:1 then you need to use group_left or group_right.

If you show the results of the two halves of the query separately then we can be more specific. That is:

sum(kafka_consumergroup_lag{cluster=~"$cluster",consumergroup=~"$consumergroup",topic=~"$topic"}) by (consumergroup, topic) 

count(up{job="prometheus.scrape.kafka_exporter"})

Sameer Modak

unread,
May 28, 2024, 8:23:21 AM5/28/24
to Prometheus Users
Hello Brian,

Actually tried as you suggested earlier but when i execute it says no data . So below are the individual query ss , so if i ran individually they give the output

Screenshot 2024-05-28 at 5.44.54 PM.png
Screenshot 2024-05-28 at 5.45.34 PM.png

Brian Candler

unread,
May 28, 2024, 10:33:46 AM5/28/24
to Prometheus Users
Those mangled screenshots are no use. What I would need to see are the actual results of the two queries, from the Prometheus web interface (not Grafana), in plain text: e.g.

foo{bar="baz",qux="abc"} 42.0

...with the *complete* set of labels, not expurgated. That's what's needed to formulate the join query.

Reply all
Reply to author
Forward
0 new messages