Skip to content

Commit

Permalink
Extract consumer group member_count as a separate metric
Browse files Browse the repository at this point in the history
Added a new consumer_group_members topic to capture number of members
in a consumer group and removed the `member_count` label from consumer_group_info

Fixes #103
  • Loading branch information
amuraru committed Aug 1, 2021
1 parent f96bc3a commit 06332a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 11 additions & 2 deletions prometheus/collect_consumer_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package prometheus

import (
"context"
"strconv"

"github.com/prometheus/client_golang/prometheus"
"github.com/twmb/franz-go/pkg/kerr"
"go.uber.org/zap"
"strconv"
)

func (e *Exporter) collectConsumerGroups(ctx context.Context, ch chan<- prometheus.Metric) bool {
Expand Down Expand Up @@ -43,12 +44,20 @@ func (e *Exporter) collectConsumerGroups(ctx context.Context, ch chan<- promethe
prometheus.GaugeValue,
float64(state),
group.Group,
strconv.Itoa(len(group.Members)),
group.Protocol,
group.ProtocolType,
group.State,
strconv.FormatInt(int64(coordinator), 10),
)
// total number of members in consumer groups
if len(group.Members) > 0 {
ch <- prometheus.MustNewConstMetric(
e.consumerGroupMembers,
prometheus.GaugeValue,
float64(len(group.Members)),
group.Group,
)
}
}
}
return true
Expand Down
10 changes: 9 additions & 1 deletion prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Exporter struct {

// Consumer Groups
consumerGroupInfo *prometheus.Desc
consumerGroupMembers *prometheus.Desc
consumerGroupTopicOffsetSum *prometheus.Desc
consumerGroupTopicPartitionLag *prometheus.Desc
consumerGroupTopicLag *prometheus.Desc
Expand Down Expand Up @@ -144,7 +145,14 @@ func (e *Exporter) InitializeMetrics() {
e.consumerGroupInfo = prometheus.NewDesc(
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "consumer_group_info"),
"Consumer Group info metrics. It will report 1 if the group is in the stable state, otherwise 0.",
[]string{"group_id", "member_count", "protocol", "protocol_type", "state", "coordinator_id"},
[]string{"group_id", "protocol", "protocol_type", "state", "coordinator_id"},
nil,
)
// Group Members
e.consumerGroupMembers = prometheus.NewDesc(
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "consumer_group_members"),
"Consumer Group member count metrics. It will report the number of members in the consumer group",
[]string{"group_id"},
nil,
)
// Topic / Partition Offset Sum (useful for calculating the consumed messages / sec on a topic)
Expand Down

0 comments on commit 06332a8

Please sign in to comment.