Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions kafka_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) {

wg.Wait()

getConsumerGroupMetrics := func(broker *sarama.Broker) {
getConsumerGroupMetrics := func(broker *sarama.Broker, processedGroups map[string]bool) {
defer wg.Done()
if err := broker.Open(e.client.Config()); err != nil && err != sarama.ErrAlreadyConnected {
klog.Errorf("Cannot connect to broker %d: %v", broker.ID(), err)
Expand All @@ -579,11 +579,14 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) {
return
}
groupIds := make([]string, 0)
e.mu.Lock()
for groupId := range groups.Groups {
if e.groupFilter.MatchString(groupId) && !e.groupExclude.MatchString(groupId) {
if e.groupFilter.MatchString(groupId) && !e.groupExclude.MatchString(groupId) && !processedGroups[groupId] {
groupIds = append(groupIds, groupId)
processedGroups[groupId] = true
}
}
e.mu.Unlock()

describeGroups, err := broker.DescribeGroups(&sarama.DescribeGroupsRequest{Groups: groupIds})
if err != nil {
Expand Down Expand Up @@ -657,7 +660,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) {
consumergroupCurrentOffset, prometheus.GaugeValue, float64(currentOffset), group.GroupId, topic, strconv.FormatInt(int64(partition), 10),
)
e.mu.Lock()
currentPartitionOffset, currentPartitionOffsetError := e.client.GetOffset(topic, partition, sarama.OffsetNewest)
currentPartitionOffset, currentPartitionOffsetError := e.client.GetOffset(topic, partition, sarama.OffsetNewest)
if currentPartitionOffsetError != nil {
klog.Errorf("Cannot get current offset of topic %s partition %d: %v", topic, partition, currentPartitionOffsetError)
} else {
Expand All @@ -673,11 +676,11 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) {
lag = currentPartitionOffset - offsetFetchResponseBlock.Offset
lagSum += lag
}

ch <- prometheus.MustNewConstMetric(
consumergroupLag, prometheus.GaugeValue, float64(lag), group.GroupId, topic, strconv.FormatInt(int64(partition), 10),
)
}
}
e.mu.Unlock()
}
ch <- prometheus.MustNewConstMetric(
Expand All @@ -702,11 +705,12 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) {
}
}
klog.Info(servers)
processedGroups := make(map[string]bool)
for _, broker := range e.client.Brokers() {
for _, server := range servers {
if server == broker.Addr() {
wg.Add(1)
go getConsumerGroupMetrics(broker)
go getConsumerGroupMetrics(broker, processedGroups)
}
}
}
Expand Down