diff --git a/prometheus/collect_consumer_groups.go b/prometheus/collect_consumer_groups.go index a3c600b..41b4dda 100644 --- a/prometheus/collect_consumer_groups.go +++ b/prometheus/collect_consumer_groups.go @@ -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 { @@ -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 diff --git a/prometheus/exporter.go b/prometheus/exporter.go index 0795c34..9ae1088 100644 --- a/prometheus/exporter.go +++ b/prometheus/exporter.go @@ -40,6 +40,7 @@ type Exporter struct { // Consumer Groups consumerGroupInfo *prometheus.Desc + consumerGroupMembers *prometheus.Desc consumerGroupTopicOffsetSum *prometheus.Desc consumerGroupTopicPartitionLag *prometheus.Desc consumerGroupTopicLag *prometheus.Desc @@ -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)