Skip to content

Commit

Permalink
Merge pull request #105 from amuraru/issue-103
Browse files Browse the repository at this point in the history
Extract consumer group member_count as a separate metric
  • Loading branch information
weeco authored Oct 12, 2021
2 parents 3f84442 + 00eb355 commit 1dd0306
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ kminion_kafka_topic_high_water_mark_sum{topic_name="__consumer_offsets"} 1.51202
```
# HELP kminion_kafka_consumer_group_info Consumer Group info metrics. It will report 1 if the group is in the stable state, otherwise 0.
# TYPE kminion_kafka_consumer_group_info gauge
kminion_kafka_consumer_group_info{coordinator_id="0",group_id="bigquery-sink",member_count="2",protocol="range",protocol_type="consumer",state="Stable"} 1
kminion_kafka_consumer_group_info{coordinator_id="0",group_id="bigquery-sink",protocol="range",protocol_type="consumer",state="Stable"} 1
# HELP kminion_kafka_consumer_group_members Consumer Group member count metrics. It will report the number of members in the consumer group
# TYPE kminion_kafka_consumer_group_members gauge
kminion_kafka_consumer_group_members{group_id="bigquery-sink"} 2
# HELP kminion_kafka_consumer_group_empty_members Consumer Group Empty Members. It will report the number of members in the consumer group with no partition assigned
# TYPE kminion_kafka_consumer_group_empty_members gauge
Expand Down
9 changes: 8 additions & 1 deletion prometheus/collect_consumer_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,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
ch <- prometheus.MustNewConstMetric(
e.consumerGroupMembers,
prometheus.GaugeValue,
float64(len(group.Members)),
group.Group,
)

// iterate all members and build two maps:
// - {topic -> number-of-consumers}
// - {topic -> number-of-partitions-assigned}
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
consumerGroupMembersEmpty *prometheus.Desc
consumerGroupTopicMembers *prometheus.Desc
consumerGroupAssignedTopicPartitions *prometheus.Desc
Expand Down Expand Up @@ -147,7 +148,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,
)
// Group Empty Memmbers
Expand Down

0 comments on commit 1dd0306

Please sign in to comment.